logo
down
shadow

How to add multiple route filters in Laravel 4.2 while using role:permission pattern?


How to add multiple route filters in Laravel 4.2 while using role:permission pattern?

By : user2955692
Date : November 22 2020, 10:40 AM
hop of those help? I suggest you use some kind of delimiter, like a ; to pass in multiple roles.
code :
'before' => 'role:administrator;moderator'
Route::filter('role', function($route, $request, $value)
{
    if(Auth::check()){
        $user = Auth::user();
        $roles = explode(';', $value);
        foreach($roles as $role){
            if($user->hasRole($role)){
                return;
            }
        }
    }
    return Response::make('Unauthorized', 403);
});


Share : facebook icon twitter icon
How to apply multiple filters on Laravel 4 route group?

How to apply multiple filters on Laravel 4 route group?


By : Jon
Date : March 29 2020, 07:55 AM
This might help you Is it possible to add multiple filters on a group route in Laravel 4? , You can:
code :
Route::group(['before' => 'auth|csrf'], function()
{
     //
});
function csrfFilter()
{
    if (Session::token() != Input::get('_token'))
    {
        throw new Illuminate\Session\TokenMismatchException;
    }
}
function authFilter()
{
    if (Auth::guest()) return Redirect::guest('login');
}

Route::filter('csrf-or-auth', function () 
{
    $value = call_user_func('csrfFilter');
    if ($value) return $value;
    else return call_user_func('authFilter');
});
Route::group(['before' => 'csrf-or-auth'], function()
{
     //
});
How to apply multiple filters on route group in Laravel 4?

How to apply multiple filters on route group in Laravel 4?


By : Prabish Thazhathepur
Date : March 29 2020, 07:55 AM
hope this fix your issue , According to your situation ...
I suggest:
code :
<?

// OEM Routes
if(Auth::check()){
    if ( (Auth::user()->type == "Distributor") AND (Auth::user()->distributor()->first()->type == 'OEM') ){

        Route::group(array('before'=>'auth'),function() {
            Route::group(array('before'=>'csrf'),   function(){ 

            // Other important routes like sign-out, dashboard, or change password should also listed here
            Route::get('/account/sign-out',array('as'=>'account-sign-out','uses'=>'AccountController@getSignOut' ));
            Route::get('/dashboard', array('as' =>'dashboard','uses'=>'HomeController@dashboard'));

            // Allow routes
            Route::get('distributors/{id}', array('uses'=>'DistributorController@show'));
            Route::get('distributors/{id}/edit', 'DistributorController@edit');
            Route::put('distributors/{id}/update', array('as'=>'distributors.update', 'uses'=>'DistributorController@update'));
            Route::get('catalog_downloads','CatalogDownloadController@index');
            Route::get('catalog_downloads/{id}/download','CatalogDownloadController@file_download');


        }); 
    }
}else{
    return Redirect::route('home'); // I assume you have this declare somewhere
}



// Not OEM Routes  
if(Auth::check()){
    if ( (Auth::user()->type == "Distributor") AND (Auth::user()->distributor()->first()->type !== 'OEM') ){

        Route::group(array('before'=>'auth'),function() {
            Route::group(array('before'=>'csrf'),   function(){ 

            // Other important routes like sign-out, dashboard, or change password should also listed here
            Route::get('/account/sign-out',array('as'=>'account-sign-out','uses'=>'AccountController@getSignOut' ));
            Route::get('/dashboard', array('as' =>'dashboard','uses'=>'HomeController@dashboard'));


            // Allow routes 
            Route::get('marketing_materials','MarketingMaterialController@index');
            Route::get('marketing_materials/{id}/download/thumb_path','MarketingMaterialController@thumb_download');
            Route::get('marketing_materials/{id}/download/media_path','MarketingMaterialController@media_download');

            Route::get('distributors/{id}', array('uses'=>'DistributorController@show'));
            Route::get('distributors/{id}/edit', 'DistributorController@edit');
            Route::put('distributors/{id}/update', array('as'=>'distributors.update', 'uses'=>'DistributorController@update'));
            Route::get('catalog_downloads','CatalogDownloadController@index');
            Route::get('catalog_downloads/{id}/download','CatalogDownloadController@file_download');


        }); 
    }
}else{
    return Redirect::route('home'); // I assume you have this declare somewhere
}
How to use any one of multiple filters in route in Laravel 4.2

How to use any one of multiple filters in route in Laravel 4.2


By : Minoey
Date : March 29 2020, 07:55 AM
this one helps. Make third filter, that will check if user is guest or admin, for example the name is guestOrAdmin. Than write a code like this:
code :
Route::group(array('before' => 'guestOrAdmin'), function() 
{
    \\all your controller functions which can be accessed by guests and admins
     Route::group(array('before' => 'guest'), function() 
    {
        \\some controller functions which can be access only by guest
    });
  Route::group(array('before' => 'admin'), function() 
    {
        \\some controller functions which can be access only by admin
    });
});
How to check logged user's role in Laravel 5.8 with route filters

How to check logged user's role in Laravel 5.8 with route filters


By : lolium
Date : March 29 2020, 07:55 AM
I wish this help you You get this error because Route::filter() was wiped away from Laravel since > 5.0, so it is trying to find an unexisting Route::$filter static property.
Right now (version 5.8 as I am writing this), the best way to do that filtering is to use middlewares.
code :
namespace App\Http\Middleware;

use Auth;
use Closure;
use Redirect;

class CheckRole
{
    public function handle($request, Closure $next)
    {
        if (Auth::user()->role !== 1) {
            return Redirect::to('/');
        }

        return $next($request);
    }
}
// Within App\Http\Kernel Class...

protected $routeMiddleware = [
    // Other middlewares...    

    'role' => \App\Http\Middleware\CheckRole::class,
];
Route->group(['middleware' => 'role'], function() {            
    Route::get('/user/edit/{id}', 'UsersController@edit');
    Route::delete('/users/delete', 'UsersController@destroy');
});
class UsersController extends Controller
{
    public function __construct()
    {       
        $this->middleware('role');
    }

    // ...
}
How can I assgin multiple role to any laravel route?

How can I assgin multiple role to any laravel route?


By : ash2015
Date : March 29 2020, 07:55 AM
hop of those help? I created one middleware to check user roles("superadmin","admin" and "user"). , You need to seperate the roles with an |.
like so:
shadow
Privacy Policy - Terms - Contact Us © ourworld-yourmove.org