Support the ongoing development of Laravel.io →
Security
Last updated 3 months 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', '[email protected]');
        Route::post('post/destroy', '[email protected]');
    });
Last updated 3 months 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 3 months 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 3 months ago.
0

Sign in to participate in this thread!

LoadForge

Your banner here too?

divdax divdax divdax Joined 3 Feb 2014

Moderators

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

Your logo here?

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

© 2022 Laravel.io - All rights reserved.