Support the ongoing development of Laravel.io →
posted 9 years ago
Security
Last updated 1 year ago.
0

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');
    });
Last updated 1 year ago.
0

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.

Last updated 1 year ago.
0

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');
Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

divdax divdax Joined 3 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.