php - Route parameter patterns on routes with similar parameters -


i have few routes takes couple of uuids parameters:

route::get('/foo/{uuid1}/{uuid2}', 'controller@action'); 

i want able verify parameters correct format before passing control off action:

route::pattern('uuid1', '^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$'); 

this works fine. however, don't want repeat pattern many times (in real case have repeated 8 times 8 different uuid route parameters).

i can't this:

route::get('/foo/{uuid}/{uuid}', 'controller@action'); 

because produces error:

route pattern "/foo/{uuid}/{uuid}" cannot reference variable name "uuid" more once.

i can lump them single function call since discovered route::patterns:

route::patterns([     'uuid1' => '^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$',     'uuid2' => '^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$', ]); 

but still repetitious. there way can bind multiple pattern keys single regular expression?

ideally i'd find way avoids this:

$pattern = 'uuid regex'; route::patterns([     'uuid1' => $pattern,     'uuid2' => $pattern, ]); 

there's no built in way handle this, , think solution found pretty nice. maybe bit more elegant this:

route::patterns(array_fill_keys(['uuid1', 'uuid2'], '/uuid regex/')); 

Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -