John Davidson

php - Multiple parametes between same Slash route

0 comments
Message:


im trying to pass 2 parameters between the same slash, if i use one parameter it works fine, but 2 is not working.


Example:
route:


Works:
Route::get('/jobpost-{title}','SomeController@show')->name('name.route');

Don't works:
Route::get('/jobpost-{title}-day-{day}','SomeController@showMore')->name('name.route.other');

I notice that if i add a slash before the parameter day it works fine, but i need to find a way (beside creating a slug column) to be able to have 2 parameters in same route.


Is that possible?



My Answer:
Yes, it is possible to have multiple parameters in the same route in Laravel. You can achieve this by defining the route with multiple parameters separated by slashes. Here's how you can modify your route to include two parameters:

php
Route::get('/jobpost-{title}-day-{day}','SomeController@showMore')->name('name.route.other');


Make sure to update your controller method `showMore` to accept both parameters:

php
public function showMore($title, $day) {
// Your code here
}


With this setup, you should be able to access the route `/jobpost-example-title-day-5` and have both parameters passed to your controller method.

Rate this post

4 of 5 based on 6140 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us