Khanh Tran
Khanh Tran

Reputation: 1826

Laravel filter with parameter in construct

I searched on Stack and see this question How to add filter parameters to controllers in Laravel?.

I have a similar question but this time, I need to pass an flexible $myparam argument, the code looks like bellow:

In Route.php

Route::filter('diffauthor',function($myparam){
    if(Authority::cannot('edit', 'postedit', $myparam))
                        return View::make('permdeny.index');
});

and in Controller:

public function __construct() {
        parent::__construct();
        $this->filter('before','diffauthor', $myparam);
    }

How do I pass $myparam base on user request?

Upvotes: 0

Views: 1543

Answers (1)

William Cahill-Manley
William Cahill-Manley

Reputation: 2405

You can only pass parameters to filters as strings:

$this->filter('before', 'diffauthor:param1,param2');

Sometimes to get around this limitation I use the Session class as a sort of temporary store, or even inspect variables that are being passed to the method by looking at the object returned by Request::route() within my filter.

Upvotes: 3

Related Questions