Milkncookiez
Milkncookiez

Reputation: 7377

Laravel RESTful route with two variables

I am trying to make a RESTful route with two variables:

Route::post('trips/{trip_id}/{user_id}', [
    'as'   => 'trips.apply',
    'uses' => 'TripsController@applyForTrip'
]);

Controller:

public function applyForTrip($trip_id, $user_id)
{
    dd('I am here! Hooray!');
}

trigger in the view:

{{ HTML::linkRoute('trips.apply', 'Get on the ride!', [$trip->id, Auth::user()->id], ['class' => 'btn btn-lg btn-success']) }}

So, I when I fire up the route, I get MethodNotAllowedHttpException. So I was wondering, perhaps I am not declaring the route correctly, or smth else, but to me it seems all alright. Any suggestions?

Upvotes: 0

Views: 60

Answers (1)

Jeff Lambert
Jeff Lambert

Reputation: 24661

When you click on an anchor link, the browser will send a GET request to the URL referenced in the href attribute. You have defined the route as a POST route in Laravel and, since Laravel can not find a GET route that matches the requested URL, you get the dreaded method not allowed exception.

Upvotes: 1

Related Questions