[英]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 ( rename 10 with long ) 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 )
code in route路线中的代码
Route::get('/product/sofa/{id}',[ProductSofaController::class,'sofa']);
code in html html 中的代码
<a href="/product/sofa/{{ $id = 10 }}">
<img loading="auto" src="{{ asset('media/category/bg-sofa.jpg') }}"
alt="Sofa and Daybed">
</a>
code in controller 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'));
}
You should use another function to do that, i had try that, and thats work you can try my solution你应该使用另一个 function 来做到这一点,我试过了,这就是工作你可以试试我的解决方案
the route:路线:
Route::get('/product/sofa/long',[ProductSofaController::class,'long']);
the view:风景:
<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>
the controller will look like this 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'));
}
You can use the Laravel slug您可以使用 Laravel 弹头
use Illuminate\Support\Str;使用 Illuminate\Support\Str;
$slug = Str::slug('Laravel 5 Framework', '-'); $slug = Str::slug('Laravel 5 框架', '-');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.