由于下面的代码 URL 看起来像:/downloadpage/34
我想让 URL 对 SEO 友好,例如:/downloadpage/slug
在表“媒体”中有一个列slug
。如何更改媒体通过 id 搜索的代码,但在 URL 中显示 slug?
routes.php 文件:
Route::get('/downloadpage/{id}', [
'as' => 'downloadpage', 'uses' => 'DownloadController@index'
下载Controller.php 文件:
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]);
}