Support the ongoing development of Laravel.io →
Configuration Architecture

Hi, sorry form my bad english! I have a doubt about how to pass a parameters in filter class. This is my filter class

class MaxIdFilter {

   public function filter( $route , $request , $id ) {

      if ($id > 200) {
         
         return Redirect::route('home', array('error' => 'maxid'));
      }
   }
}

And this is a route:

Route::get('/{id}', array(
    
    'as'        => 'idhandler',
    'before'    => 'maxId:50',
    'uses'      => 'IdController@showDataId'
    
));

Ok, now I have used a static value of id (50) but I would like pass the real value of ID. I had try this:

....
 'before'    => 'maxId:'.$id,
....

but obviously in array() $id don't exists:

ErrorException

Undefined variable: id

How can I resolve?

Last updated 3 years ago.
0

check your $request in the filter

I believe

$request->get('id');

should give you the id

your before should look like

....
'before'    => 'maxId',
....
Last updated 3 years ago.
0

Hi zenry,

these calls work:

$route->getParameter('id')
Route::input('id')

As long as

$request->get('id')

return null.

But I would like to know if there a way to pass an argument directly within the filter, since the filter method accept a third parameter....

Surely there must be a way....

Last updated 3 years ago.
0
class MaxIdFilter {

   public function filter( $route , $request ) {

      if ($route->getParameter('id') > 200) {

         return Redirect::route('home', array('error' => 'maxid'));
      }
   }
}
Last updated 3 years ago.
0

what I would like to do, is use the route for "send" the parameter at the filter through use of this syntax:

Route::get('/{id}', array(

    'as'        => 'idhandler',
    'before'    => 'maxId:HERE_ID_PARAMETER',
    'uses'      => 'IdController@showDataId'

));

instead, the examples shown so far, take the parameter directly in the filter class through method calls:

$route->getParameter('id')
Route::input('id')
Last updated 3 years ago.
0

Sign in to participate in this thread!

PHPverse

Your banner here too?

matiux matiux Joined 28 Feb 2014

Moderators

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

Your logo here?

Laravel.io

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

© 2025 Laravel.io - All rights reserved.