2017-04-20 102 views
1

我正在使用揹包在我的項目中創建管理面板。我有兩種類型的用戶,一種是Superadmin,另一種是admin。我只是想給權限,以超級管理員,他可以列出,添加,編輯從所有數據庫中的行..根據laravel揹包中的用戶登錄獲取數據

但管理員只能編輯,刪除,並列出了自己創造的那些行..

所以請幫助我,我是新的拉拉維爾揹包?

回答

0

過濾您在實體的CrudController的setup()方法中顯示的結果,然後禁止訪問更新/銷燬方法。

你的結果可能是這個樣子:

public function setup() 
{ 
    // take care of LIST operations 
    if (\Auth::user()->hasRole('admin')) { 
     $this->crud->addClause('where', 'author_id', '=', \Auth::user()->id); 
    } 
} 

此外,您需要將您的檢查和update()方法destroy()內,不允許管理員刪除別人的條目。

// place this both inside your update() and inside your destroy() method 
if (\Auth::user()->hasRole('admin') && $this->crud->entry->author_id!=\Auth::user()->id) { 
    abort(405); 
} 

希望它有幫助。

+0

thanx爲你解答。但我只是不想顯示編輯頁面。那麼我應該把這個檢查放在哪裏..? –

+0

它也顯示錯誤 - 嘗試獲取非對象的屬性在我寫$ this-> crud-> entry_created_by的行中。讓我感到困惑 –

相關問題