[英]how i can remove id parameter in url laravel 8
how to change or remove the id value used in the url to call certain data, when this url appears localhost:8000/product/sofa/10 i want other users to see the url just like this localhost:8000/product/sofa or localhost :8000/product/sofa/long ( 将 10 重命名为 long )
路线中的代码
Route::get('/product/sofa/{id}',[ProductSofaController::class,'sofa']);
html 中的代码
<a href="/product/sofa/{{ $id = 10 }}">
<img loading="auto" src="{{ asset('media/category/bg-sofa.jpg') }}"
alt="Sofa and Daybed">
</a>
controller 中的代码
public function sofa(Request $request, $id){
$frame = frames::where('pf_product_category_id',[$id,16])
->where('pf_status',true)->with('linkProducts')
->get();
return view('frontend/sofa',compact('frame'));
}
你应该使用另一个 function 来做到这一点,我试过了,这就是工作你可以试试我的解决方案
路线:
Route::get('/product/sofa/long',[ProductSofaController::class,'long']);
风景:
<form method="POST" action="/product/sofa/long">
<input type="hidden" name="link_id" id="link_id" value="{{ $id = 10 }}">
<button type="submit" class="btn btn-primary btn-block">Input</button>
</form>
controller 看起来像这样
public function long(){
$request = [
'li' => $this->request->getPost('link_id'),
];
$frame = frames::where('pf_product_category_id',[$id,16])
->where('pf_status',true)->with('linkProducts')
->get();
return view('frontend/sofa',compact('frame'));
}
您可以使用 Laravel 弹头
使用 Illuminate\Support\Str;
$slug = Str::slug('Laravel 5 框架', '-');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.