如何将模型实际传递给过滤器?
我有一个表单,允许用户具有足够的权限来编辑和保存图书。
Route::model('book', 'Book');
Route::get('/edit/{book}', array('before' => 'my_filter', 'uses' => 'BookController@showForm'));
Route::filter('my_filter', function() {
// check if authenticated has enough privilege to edit a book
// Would like to do something like $book->AuthorID == Auth()::user()->AuthorID
});
有什么建议吗?谢谢!
答案 0 :(得分:1)
Route::filter('my_filter', function($route) {
$book = $route->getParameter('book');
if( $book->AuthorID == Auth()::user()->AuthorID){
// .......
}
});