将模型传递给过滤器
Passing model to filter
如何将模型实际传递给过滤器?
我有一个表单,允许具有足够权限的用户编辑和保存一本书。
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
});
有什么建议吗?谢谢!
Route::filter('my_filter', function($route) {
$book = $route->getParameter('book');
if( $book->AuthorID == Auth()::user()->AuthorID){
// .......
}
});
如何将模型实际传递给过滤器?
我有一个表单,允许具有足够权限的用户编辑和保存一本书。
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
});
有什么建议吗?谢谢!
Route::filter('my_filter', function($route) {
$book = $route->getParameter('book');
if( $book->AuthorID == Auth()::user()->AuthorID){
// .......
}
});