laravel 4 using wildcards in the url for routes spanning arbitrary sub-directories

StackOverflow https://stackoverflow.com/questions/19964446

  •  30-07-2022
  •  | 
  •  

Pergunta

I have a route:

Route::get('/{slug}c{id}','Category@index');

which works for http://domain.tld/arbitrarycategory-c22

but I'd like to make a wildcard route that matches any arbitrary sub directory as well. My controller only cares about the -c{id} portion of the route, anything before that is arbitrary and ignored. I'm looking for one route that would match these two:

http://domain.tld/arbitrarycategory-c22
http://domain.tld/parentcategory/childcategory/category-c22

Any ideas?

Foi útil?

Solução

Custom route model binding :)

<?php
Route::get('{parentCategory}/...', 'controller@method');

And bind 'parentCategory' to the route, see: http://laravel.com/docs/routing#route-model-binding. And add some more bindings for more layers.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top