2 months agoby Carlos

Add slug to old tables

This is my route Route::get('itinerary/{slug}/{id?}', 'TourDetailsController@show');

This is my show controller

public function show($slug, $id){ $tour =TourDetail::find($id); $tourCities =TourDetail::find($id)->tourCities; $incl=(string)TourDetail::find($id)->inclExcl->where('type',true); $excl=(string)TourDetail::find($id)->inclExcl->where('type',false);

return view('tourdetails.show')->with('tour',json_decode($tour,true)) ->with('tourCities',json_decode($tourCities,true)) ->with('incl',json_decode($incl,true)) ->with('excl',json_decode($excl,true));

} With this configuration, the burning url looks like this: http://domain.com/itinerary/trip-name/1

What I want is to have the url like this http://domain.com/itinerary/trip-name/

With only one table I can make it, but in my controller I have 3 tables tour_details tour_cities incl_excls

How can I solve it? Do I have to add slug field to all the tables? It is possible to keep the id's and use the slug of the tour_details table to generate the url? Or what could be the best solution, taking into account that everything works well using id's?

I hope your help.

Regard/Carlos Cusco-Perú

Ask Question
Most Visited