Laravel存储库类App \ Repository \ User不存在

时间:2019-05-19 22:18:51

标签: laravel

您好,我想在Laravel 5.8项目中使用自己的存储库类 我在App File中创建了文件Repository,并在该文件中添加了一个名为ConversationRepository的类 这是我的课程:

<?php

namespace App\Repository;

class ConversationRepository{

    private $user;

    public function __construct(User $user){

        $this->user=$user;
    }

    public function getConversation(int $userId){
       return  $this->user->newQuery()
       ->select('name','id')
       ->where('id','!=',$userId)
       ->get();
    }
}

然后当我在控制器上使用它时:

<?php

namespace App\Http\Controllers;

use App\User;
use Auth;
use Illuminate\Http\Request;
use App\Repository\ConversationRepository;



class ConversationsController extends Controller
{       
    private $r;
    private $auth;

    public function __construct(ConversationRepository $conversationRepository,AuthManager $auth){
        $this->r = $conversationRepository;
        $this->auth = $auth;
    }

    public function index(){


        return view('conversation.index',[
            'users'=>$this->r->getConversation($this->auth->user()->id)
        ]);

    }
    public function show(User $user){

        return view('conversation.show',['users'=>$this->r->getConversation(
            $this->auth->user()->id),
             'user'=>$user
             ]);
    }

    public function store(User $user){

    }
}

我得到了错误

Class App\Repository\User does not exist

1 个答案:

答案 0 :(得分:1)

显然,您忘记在use App\User;文件中添加class ConversationsController