Neethu
Neethu

Reputation: 134

Class App\Repositories\UserRepository does not exist

<?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?

Upvotes: 4

Views: 18633

Answers (10)

Yernar
Yernar

Reputation: 1

Just refactor UserRepository class to for example MyUserRepository , only this one solved my problem

Upvotes: 0

ChinhNV
ChinhNV

Reputation: 351

Change your composer.json file.

"autoload": {

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

composer dump-autoload

=> Done

Upvotes: 1

M Shafaei N
M Shafaei N

Reputation: 449

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.

Upvotes: 0

Prafulla Kumar Sahu
Prafulla Kumar Sahu

Reputation: 9691

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.

Upvotes: 0

Botea Florin
Botea Florin

Reputation: 633

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

Upvotes: 0

Syed Nazir Hussain
Syed Nazir Hussain

Reputation: 441

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

composer dump-autoload

Upvotes: 0

Shabeer K
Shabeer K

Reputation: 1617

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

   composer install

Upvotes: 0

Kresimir Plese
Kresimir Plese

Reputation: 3665

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!

Upvotes: 0

Sari Yono
Sari Yono

Reputation: 577

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

Upvotes: 1

Moppo
Moppo

Reputation: 19285

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

Upvotes: 5

Related Questions