how i can remove id parameter in url laravel 8

Viewed 43

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 )

code in route

Route::get('/product/sofa/{id}',[ProductSofaController::class,'sofa']);

code in 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

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'));
}
1 Answers

You should use another function to do that, i had try that, and thats work you can try my solution

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

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'));
}
Related