How can I pass parameter from Route to Filter in laravel

0 votes

I am using the laravel framework. If I have the following route:

Route::get('/test/{param}', array('before'=>'test_filter', 'SomeController@anyAction'));

And this filter:

Route::filter('test_filter', function() {
    $param = [Get the parameter from the url];
    return "The value is $param";
});

How can I pass parameters to the filter so that when visiting /test/foobar I would get a page saying: "The value is foobar"?

Dec 4, 2020 in Laravel by kartik
• 37,520 points
471 views

1 answer to this question.

0 votes

Hii,

Filters can be passed parameters, like the Route object or the Request:

Specifying Filter Parameters

Route::filter('age', function($route, $request, $value)
{
    //
});

Hope it helps!!

Thank you!!

answered Dec 4, 2020 by Niroj
• 82,760 points

Related Questions In Laravel

0 votes
1 answer

How to pass data through URL and access through controller in Laravel?

Hello, You can  first refer how to  Create controller through ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,760 points
6,915 views
0 votes
1 answer

How to pass CSRF token with ajax request in Laravel?

Hey, In between head, tag put <meta name="csrf-token" ...READ MORE

answered Mar 24, 2020 in Laravel by Dey
11,266 views
0 votes
1 answer

.How to turn off CSRF protection for a particular route in Laravel?

Hey, We can add that particular URL or ...READ MORE

answered Mar 24, 2020 in Laravel by Niroj
• 82,760 points
2,041 views
0 votes
1 answer

How to get a list of registered route paths in Laravel?

Hello, Route::getRoutes() returns a RouteCollection. On each element, you can ...READ MORE

answered Mar 31, 2020 in Laravel by Niroj
• 82,760 points
815 views
+1 vote
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,760 points
7,876 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,760 points
892 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,760 points
712 views
+1 vote
1 answer

What are named routes in Laravel and How can specify route names for controller actions?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,760 points
8,363 views
0 votes
1 answer

How can I serve a single HTML page from the Laravel public folder without having to use the .html extension?

Hello @kartik, You may rename the test folder ...READ MORE

answered Nov 12, 2020 in Laravel by Niroj
• 82,760 points
652 views
0 votes
1 answer

How to pass URL param in Laravel?

Hello, First you have to go to routes ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,760 points
3,104 views