嗨我已经在laravel中设置了一个存储库,当我自己查询项目表时,例如return Project::all();
我返回数据库中的所有记录。不过,我想查询的用户记录的记录,并只检索那些记录,所以我这样做,因为这样return Auth::user()->projects;
但是我这样做,当我在我的laravel日志中出现以下错误:laravel知识库查询auth用户记录
[2014-09-01 20:26:44] production.ERROR: exception
'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Class
'Acme\Repositories\Auth' not
found' in /media/sf_Sites/tempus/app/Acme/Repositories/DbProjectRepository.php:17
Stack trace:
#0 [internal function]: Illuminate\Exception\Handler->handleShutdown()
#1 {main} [] []
我的完整存储库是如下:
<?php
namespace Acme\Repositories;
use Project;
class DbProjectRepository implements ProjectRepositoryInterface {
public function getAll()
{
return Auth::user()->projects;
}
}
项目控制器
public function index()
{
$projects = $this->project->getAll();
echo View::make('projects.index', compact('projects'));
}
项目视图
@if (Auth::check())
@if (count($projects) > 0)
@foreach ($projects as $project)
{{ $project->project_name }}
@endforeach
@else
<p>No records, would you like to create some...</p>
@endif
@endif
有谁知道我做错了什么?希望能得到一些指导。
如果您使用的是Laravel的Auth,您可以尝试'\ Auth :: user()'(在Laravel的核心之前添加'\'类。 – JofryHS 2014-09-01 22:37:50