You can do this by using groups in your routes file.
You can just make a filter "beforeDestory" and make a group that applies the filter to all those routes:
Route::group(array('before' => 'authDestory'), function()
{
Route::post('page/destroy', 'PageController@postDestroy');
Route::post('post/destroy', 'PostController@postDestroy');
});
DivDax,
You could use the following sentence:
//app/filters.php
Route::filter('destroyfilter', function()
{
//The filter logic here
});
//app/routes.php
Route::when('*/destroy', 'destroyfilter');
Hope it helps you.
I don't want to update my routes.php to filter all destroy methods. The routes should be clean as possible.
@codeATbusiness: This doesn't work for resource routes.
Thanks for your hints. Here is my solution:
// filters.php
Route::filter('delete', function($route, $request)
{
$action = $route->getAction()['controller'];
if(str_contains($action, 'destroy'))
{
if(!Entrust::hasRole('Admin'))
return Redirect::back()->withError('Access denied!');
}
});
Route::when('*', 'delete');
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community