3
votes
<?php

namespace App\Http\Controllers;


use Illuminate\Contracts\Auth\Guard;
use Laravel\Socialite\Contracts\Factory as Socialite; 
use App\Repositories\UserRepository;


class SocialController extends Controller
{
    /**
     * Redirect the user to the GitHub authentication page.
     *
     * @return Response
     */

    private $socialite;
     private $auth;
     private $users;

     public function __construct(Socialite $socialite, Guard $auth, UserRepository $users) {   
        $this->socialite = $socialite;
        $this->users = $users;
        $this->auth = $auth;
    }
}

This is my controller. While I'm loading this controller it showing an error like

"ReflectionException in Container.php line 791: Class App\Repositories\UserRepository does not exist".

Can anyone suggest me a solution?

10
Is there any solution? I am facing similar error in Laravel 5.8Kamran Syed

10 Answers

4
votes

Probably a namespace issue

Check the path of your UserRepository file class. It should be:

app/Repositories/UserRepository.php

And inside the class file you need to use this namespace:

namespace App/Repositories;

This should work

1
votes

you would want to do composer dump-autoload and it will fix your issue given that you have all your namespaces / class names correctly

1
votes

I had a fatal error in my repository that caused this error. It tooks me hours to figured it out.....

0
votes

The strange thing I had when such error occurred is that I had space between keyword namespace and App\Repositories; Once removed, it all worked fine!

0
votes

in case seems like this, delete the vendor folder and re-install composer

   composer install
0
votes

Make sure your class namespace is correct or you can also run this command below

composer dump-autoload
0
votes

If you have some syntax errors in that class, the message is the same as class not found.

0
votes

If someone is facing this error. I think, you may get this error, if your Repository class is not able to access your model, just add use App\User; at top and the error should go.

0
votes

I had such problem when I tried to re-install Bagisto (on Laravel). I deleted the .env file in the project root and this solved the issue.

0
votes

Change your composer.json file.

"autoload": {

 "autoload": {
    "classmap": [
       "database",
       "app/Repositories"
 ],

composer dump-autoload

=> Done