0

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?

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.