Reputation: 67
how to remove question mark form url in laravel i use laravel 5.4 and i get this trey to use query in the link but it don't work http://localhost/shooping-cart/public/add-to-cart/id?1
i want to remove id and question mark form url i use laravel 5.4
Route::get('/add-to-cart/{id}', [
'uses' => 'ProductController@getAddToCart',
'as' => 'product.addToCart'
]);
Upvotes: 3
Views: 3121
Reputation: 1431
I think this is just the way Laravel constructs the URL. Its more of an aesthetic than functional choice. If you do not wish to see a question mark in your url when performing GET request then use a named route with parameters.
<a href="{{ route('questions.show',['question' => $task->id]) }}">View</a>
If you access your controller by matching URL thru the router class.
<form method="get" action="/questions/{{$task->id}}">
<button type="submit" class="btn btn-info btn-sm">View</button>
</form>
You will see a question mark "?" appended to the end of your URL.
Upvotes: 0
Reputation: 101
Use ? mark after id like {id?}
And in the view file, generate link like this..
<a href="{{ route('product.addToCart') }}/your_id">Link Name</a>
It will definitely work.
Route::get('/add-to-cart/{id?}', [
'uses' => 'ProductController@getAddToCart',
'as' => 'product.addToCart'
]);
Upvotes: 1
Reputation: 163758
Looks like the problem is in the way you generate the link. For this route you should use route()
helper like this:
{{ route('product.addToCart', $productId) }}
Or create a link manually:
{{ url('add-to-cart/'.$productId) }}
Upvotes: 1