skip to Main Content

I have project in laravel 10 with kyslik/column-sortable.
When I get route:

Route::get("/test", [searchEngineController::class, 'sort']);

and in searchEngineController::sort:

 public function sort() {
        $products = Products::sortable()->paginate(5);
        return view('test', compact('products'));
    }

and in view:

<table class="table table-bordered">
   <tr>
      <th width="80px">@sortablelink('id')</th>
      <th>@sortablelink('Name')</th>
      <th>@sortablelink('Second_data')</th>
   </tr>
      @foreach($products as $key => $product)
   <tr>
      <td>{{ $product->id }}</td>
      <td>{{ $product->name }}</td>
      <td>{{ $product->second_data }}</td>
   </tr>
      @endforeach
   <table>

everything works well – when I click on @sortable link it sorts.

BUT when I got to <form in view, and send it to POST route, where I get data from DB, and compact the search data to view:

 public function sort2(Request $request) {
        $products = Products::sortable()
            ->where("col", 'like', '%'.$request->search.'%')
            ->paginate(5)
        return view('test', compact('products'));
    }

and click on @sortablelink. it return:
The GET method is not supported for route >>route-Name<<. Supported methods: POST.

How to do it, to work it on post route?

2

Answers


  1. i have never used kyslik/column-sortable but following the error you can create a get route that does the same work as POST with the same URL

    Route::get("/test", [searchEngineController::class, 'sort']);
    Route::post("/test", [searchEngineController::class, 'sort2']);
    

    hope my idea will help

    Login or Signup to reply.
  2. You can change your route to be POST, like:

    Route::post("/test", [searchEngineController::class, 'sort']);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search