Error with complementary routes in Laravel 4

1

Initially, I created the following route (1st search):

Route::get('/buscar/profissoes/{city_id_slug?}', array('as' => 'neighborhoods.city', 
    'uses' => 'NeighborhoodsController@getIndexCity'));

Then the URL looks like this at the end:

 http://example.com/buscar/profissoes/1-uberlandia

After, I created the second aroat (2nd search - continued)

Route::get('/buscar/profissionais/{city_id_slug}/{neighborhood_id_slug}/
{profession_id_slug}', array('as' => 'professionals.search', 'uses' => 'ProfessionalsController@getSearch'));

Then the URL should look like this:

 http://example.com/buscar/profissionais/1-uberlandia/15-santa-monica/1-pedreiro

But since the above URL is generated dynamically, it does not initially have the last 2 parameters. They will be added when you click submit. Anyway, I added the parameters, just as test and did not work:

URL::route('professionals.search', array($city_id_slug, $city_id_slug, $city_id_slug))

Then Laravel returns the following:

Symfony \ Component \ Routing \ Exception \ RouteNotFoundException

Unable to generate a URL for the named route "http://example.com/buscar/profissionais/1-uberlandia/1-uberlandia/1-uberlandia" as such route does not exist.

What is the right way to do this? And what is wrong with my routes, that they are different, and that even forcing the last 2 parameters with the number 1, did not work?

    
asked by anonymous 17.12.2013 / 12:11

3 answers

3

You can submit via POST everything to search for it:

  cidade/{city_id_slug}/bairro/{neighborhood_id_slug?}/profissao/{profession_id_slug?} 

And redirect to a GET route with the URL treated.

I believe it is a quiet solution to be implemented. And it generates more control than you are doing.

    
17.12.2013 / 12:40
1

Patrick,

Via laravel it will not be possible to generate the second route correctly without the parameters.

I already had to do something like this, and what I did was generate the first part (its route 1), and I added manually via javascript (I no longer have access to the project, so I can not post the code to solve the problem).

Tip: The 2nd route should come first, because if it finds the "default" first it will stop at it.

    
17.12.2013 / 12:24
1

Interpret each route as distinct, so you can create 3 routes: one that responds to requests with 1 parameter, another with two and another with three ...

    
17.12.2013 / 13:21