簡體   English   中英

我如何刪除 url laravel 8 中的 id 參數

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM