Wednesday, March 28, 2018

Want to show name as a parameter instead of id in the URL field in Laravel - development

Want to show name as a parameter instead of id in the URL field in Laravel

I don’t want to show /route_name/{id} in the URL field of my Laravel project. Instead of that I want to show /route_name/{name} and also pass the id in the back-end to the controller.

Suppose I have a view department.blade.php. Now click on knee pain from the menubar for seeing the details. Here is my view code

<a href=">
   
</a>"

After click the knee pain a route called. Here is the route

Route::get('/home_services_under_department/{id}', 'frontendDepartmentController@home_services_under_department');

Here is the home_services_under_department method format

public function home_services_under_department($id){}

Here is my URL in browser
http://url/home_services_under_department/2

But I don’t want to see the id after home_services_under_department, I want to see the name knee-pain after home_services_under_department as a parameter like

http://url/home_services_under_department/knee-pain 

and also want to pass the id to the controller method.

Is it possible in Laravel ?



from Laravel Questions and Answers https://laravelquestions.com/php/want-to-show-name-as-a-parameter-instead-of-id-in-the-url-field-in-laravel/
via Lzo Media

No comments:

Post a Comment