Query :
Due to this below code url looks like : /downloadpage/34 I want to make url seo friendly like : /downloadpage/slug
In table 'media' there is a column - slug
How to change in this code that media searches by id, but in url it shows slug?
routes.php file :
Route::get('/downloadpage/{id}', [
    'as' => 'downloadpage', 'uses' => 'DownloadController@index'
DownloadController.php file :
public function index($id){
    $images   = DB::table('media')->where("id", "=", $id)->get();
    $popular  = DB::table('media')->orderBy('count_download', 'DESC')->take(5)->get();
    $mostlike = DB::table('media')->orderBy('count_like', 'DESC')->take(5)->get();
    $alsolike = DB::table('media')->orderByRaw("RAND()")->where("id", "!=", $id)->take(3)->get();
    $settings = Setting::first();
    $previous = DB::table('media')->where('id', '<', $id)->max('id');
    $next     = DB::table('media')->where('id', '>', $id)->min('id');
    $imgshare = DB::table('media')->where("id", "=", $id)->first();
    return view('download.downloadpage', ['images'=>$images , 'popular'=>$popular, 'mostlike'=>$mostlike, 'alsolike'=>$alsolike, 'settings'=>$settings, 'previous'=>$previous, 'next'=>$next, 'imgshare'=>$imgshare]);
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire