'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
Solution 1:[1]
I usually check in bootstrap/cache/config.php for the package, sometimes after composer remove nameofthepackage, the package is still listed there
Solution 2:[2]
You have to register the service provider in config/app.php. https://laravel.com/docs/5.3/providers#registering-providers
Solution 3:[3]
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;
Solution 4:[4]
Working for me. You can try it!
Remove "laravel/ui" reference and its provider from packges.php file.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | herry swastika |
Solution 2 | LorenzSchaef |
Solution 3 | Kaleemullah |
Solution 4 |