mercredi 18 août 2021

Access Laravel URL with ID only (Best approach)

My application is made in laravel 5.8, I want to ask about the best approach for a unique scenario where I want to display some of my customer profiles like

https://www.example.com/1234

I know that in laravel I have to give a unique identifier before the URL like https://www.example.com/profile/1234 so that it know which function to look for. But for some reason I have to build the above URL.

I tried it directly like:

Route::get('/{id}', 'ExampleController@myfunction')->name('profiler');

But this only works when I put it in bottom of my Routes file. If I place it somewhere in the middle or top. All other links like https://www.example.com/about-us stops working.

My Question is:

  • What is the best approach to achieve something like this. (Is it fine that I keep it in the bottom of the route file or will it be some kind of threat or any drawbacks to this approach?)
  • Should I use this approach or add a unique identifier instead.

I would really want to use the URL I mentioned in the start of the question.

Thank you all in advance for helping me.

Peace :)



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire