I am using Repository pattern in laravel to fetch records from a table but getting error like
"Target [App\Repositories\ThirdPartyRepository] is not instantiable while building [App\Http\Controllers\Dashboardcontroller]."
This is the following structure I have
app ->
Repositories
->Thirdpartyrepository.php
-> Thirdpartyrepositoryinterface.php
-> ThirdpartyServiceProvider.php
Thirdpartyrepositoryinterface.php
namespace App\Repositories;
interface ThirdpartyRepositoryInterface
{
public function getAll();
}
Thirdpartyrepository.php
namespace App\Repositories;
abstract class ThirdPartyRepository implements ThirdpartyRepositoryInterface
{
public function getAll(){
$getcmp= DB::table('xyz')
->orderBy('id', 'desc')
->select('name', 'id', 'created_at')
->get();
return $getcmp;
}
}
ThirdpartyServiceProvider.php
namespace App\Repositories;
use Illuminate\Support\ServiceProvider;
class ThirdpartyServiceProvider extends ServiceProvider
{
public function register(){
$this->app->bind(
'App\Repositories\ThirdpartyRepositoryInterface',
'App\Repositories\ThirdPartyRepository'
);
}
}
Dashboardcontroller.php
use App\Repositories\ThirdPartyRepository;
protected $thirdparty;
public function __construct(ThirdPartyRepository $thirdparty){
$this->thirdparty= $thirdparty;
}
public function getproducts(){
$getCompanies=$this->thirdparty->getAll();
dd ($getCompanies);
}