Naveen Kumar
Naveen Kumar

Reputation: 1626

how to fix Service provider class not found when using repository?

I am new to repository in laravel and trying to work on it , But when i run the application it throws the error

Class 'App\Repositories\User\UserRepoServiceProvider' not found

My interface and repository files are located in App\Repositories\User where Service Provider is also located

Here is my service provider

namespace App\Repositories\User

use Illuminate\Support\ServiceProvider;

class UserRepoServiceProvider extends ServiceProvider

{

public function register()
{

$this->app->bind('App\Repositories\User\userinterface','App\Repositories \User\userrepository');
}
}

Here is my userrepository.php

namespace App\Repositories\User

use App\Repositories\User\userinterface;
use App\car;

class userrepository implements userinterface
{

public function __construct(car $car){

$this->car = $car;
}

public function get($id)
{

return $this->car->findCar($id);
}

public function delete($id)
 {

return $this->car->deleteCar($id);
}


}

Here is my interface userinterface.php

namespace App\Repositories\User;

interface userinterface{

public function get($id);

public function delete($id);
}

I have also registered it in config/app.php file

App\Repositories\User\UserRepoServiceProvider::class

I did composer dump-autoload -o but no use. I cannot do composer update , when i do it throws the same error

Upvotes: 1

Views: 8351

Answers (4)

Muhammad Bilal
Muhammad Bilal

Reputation: 3008

Working for me. You can try it!

Remove "laravel/ui" reference and its provider from packges.php file.

enter image description here

Upvotes: -1

Kaleemullah
Kaleemullah

Reputation: 544

I'm facing this problem Class 'App\Respositories\BackendServiceProvider' not found It was due to spelling mistake in config/app.php file. I changed Respositories to Repositories and open this BackendServiceProvider and changed namespace also. so problem has been solved.

Respositories to Repositories
namespace App\Respositories to namespace App\Repositories;

Upvotes: -1

herry swastika
herry swastika

Reputation: 53

I usually check in bootstrap/cache/config.php for the package, sometimes after composer remove nameofthepackage, the package is still listed there

Upvotes: 3

LorenzSchaef
LorenzSchaef

Reputation: 1543

You have to register the service provider in config/app.php. https://laravel.com/docs/5.3/providers#registering-providers

Upvotes: 2

Related Questions