How to transform the route shown in Laravel?

1

I'm new using Laravel and my question is this: How can I do so when this route is requested:

miproyecto.com/user/23

is transformed to:

miproyecto.com/victor-hugo

I just need to do that, and I managed to get the data thrown depending on the user number. I would appreciate it if you could help me, I just need that to finish my final project. Thanks for your help.

    
asked by Victor Hugo 04.05.2017 в 05:30
source

1 answer

0

You could install a package like Sluggable: link

Once installed you can do what you want, just add a route like

Route::get('{slug}', 'MyController@show')->name('show.user');

You must also add the respective field for the slug to the table in the database.

In the controller you handle it with the findBySlug() method:

public function show($slug)
{
    $user = User::findBySlug($slug);

    // 
}

You find everything in the package documentation.

    
answered by 04.05.2017 / 05:59
source