嗨我已經在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