Gaurav Mehta
Gaurav Mehta

Reputation: 1153

Route definition not working in Laravel

I have 2 routes in my routes file.

Route::get('/deals/{merchant_name}?c={deal_id}', ['uses' => 'dealsvisibleController@index']);
Route::get('/deals/{merchant_name}', ['uses' =>'dealsController@index']);

Both routes are calling on a different controller function. The first route is however not working.

I am trying this in a 3rd controller.

 return redirect('deals/'.$merchant_name.'?c='.$deal_id);

However, when the page redirects, it is calling dealsController@index and not dealsvisibleController@index

Can someone help me with why this is happening.

Upvotes: 0

Views: 96

Answers (1)

jedrzej.kurylo
jedrzej.kurylo

Reputation: 40909

Laravel's router considers only path when matching URLs to your routes. Therefore, if you redirect to deals/someMerchant?c=someDealId then it uses deals/someMerchant to match the URL.

You'll need to define the first route as deals/{merchant_name}/{deal_id} in order for this routing to work as you want it to.

Upvotes: 1

Related Questions