laravel 类 App\Repositories\UserRepository 不存在

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34672612/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 13:00:22  来源:igfitidea点击:

Class App\Repositories\UserRepository does not exist

phplaravellaravel-5repositorylaravel-5.1

提问by Neethu

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

“Container.php 第 791 行中的 ReflectionException:Class App\Repositories\UserRepository 不存在”。

Can anyone suggest me a solution?

谁能建议我一个解决方案?

回答by Moppo

Probably a namespace issue

可能是命名空间问题

Check the path of your UserRepositoryfile class. It should be:

检查UserRepository文件类的路径。它应该是:

app/Repositories/UserRepository.php

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

在类文件中,您需要使用此命名空间:

namespace App/Repositories;

This should work

这应该工作

回答by Sari Yono

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

你会想要这样做composer dump-autoload,它会解决你的问题,因为你拥有正确的所有命名空间/类名

回答by JGL

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

我的存储库中有一个导致此错误的致命错误。我花了几个小时才弄明白......

回答by Shabeer Sha

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

如果看起来像这样,请删除供应商文件夹并重新安装作曲家

   composer install

回答by Syed Nazir Hussain

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

确保您的类命名空间正确,或者您也可以在下面运行此命令

composer dump-autoload

回答by Botea Florin

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

如果您在该类中有一些语法错误,则消息与未找到类相同。

回答by Prafulla Kumar Sahu

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.

如果有人面临这个错误。我认为,您可能会收到此错误,如果您的 Repository 类无法访问您的模型,只需use App\User;在顶部添加,错误就会消失。

回答by M Shafaei N

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.

当我尝试重新安装 Bagisto(在 Laravel 上)时遇到了这样的问题。我删除了项目根目录中的 .env 文件,这解决了问题。

回答by Kresimir Plese

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

发生此类错误时,我遇到的奇怪事情是关键字namespaceApp\Repositories;一旦删除之间有空格,一切正常!