I am following this link to implement it
I did below steps to implement the Contract in my existing class.
Below is the class where I will write some logic also before sending it to controller
class RoleBL implements IRole {
public function All() {
return (new RoleDb())->All();
}
}
Database Function
class RoleDb {
public function All() {
$Roles = \App\Models\Role\RoleModel
::all();
return $Roles;
}
}
Interface
interface IRole {
public function All();
}
Service Provider class
class RoleServiceProvider extends \Illuminate\Support\ServiceProvider {
public function register()
{
$this->app->bind('App\Contract\Role\IRole', function($app){
return new \App\Classes\BusinessLogic\Role\RoleBL($app['HttpClient']);
});
}
}
Controller - Constructor
public function __construct(\App\Classes\Role\IRole $_roles) {
parent::__construct();
$roles = $_roles;
}
When I ran the site, I got following error.
Target [App\Contract\Role\IRole] is not instantiable while building [App\Http\Controllers\Website\Membership\MembershipController].
Please guide me if I missed anything?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire