0

i have a problem in delete an order:

here the form where press on cancel to delete the order:

<form action="{{route('user.orders.delete', $order->id)}}" method="POST"
                                  onsubmit="return confirm('Are you sure?');">
                                @method('DELETE')
                                @csrf
                                <button
                                    type="submit" class="mt-8 mb-4 py-2 px-14 rounded-full
                                    bg-red-900 text-white tracking-widest hover:bg-blue-800
                                    transition duration-200">
                                    Cancel
                                </button>
                            </form>

this is my router:

 Route::delete('user/orders/delete/{order}', [OrderController::class, 'delete'])->name('user.orders.delete');
  • OrderController : delete function:

    public function delete(Order $order) { try { unlink(public_path().'/storage/orders/files/'.$order->file); $order->delete(); }catch(\Exception $e) { return redirect()->back()-with('status', 'you cannot delete this item');

          }
          return redirect()->back()->with('status', 'product deleted succefully');
      }
    

so when click on the button (cancel) just go to the right url : when 21 is the order id

http://127.0.0.1:8000/user/orders/delete/21

and it is just not found page!!! and nothing deleted!!!

3
  • So in the network tab the delete request is 404 not found? Commented Aug 23, 2021 at 12:29
  • yes right...... Commented Aug 23, 2021 at 12:31
  • It is a delete request and does php artisan route list show on the route in question Commented Aug 23, 2021 at 12:32

1 Answer 1

0

i think your app routes is cached

try to run the fallowing command (in cmd or terminal) to see all the routes, this will show registered routes and errors if exist:

php artisan route:list

if the route doesnt exist in route list, the route list may be cached. try the fallowing command to clear route cache:

php artisan route:clear

and then run app and test the route.

If you do not have another problem in coding or naming variables, the program will be fixed properly

*if all o the above is ok, it seems your apache config is not configure to delete request(for route delete method ) and you must change .htaccess requests LIMIT like the fallowing sample to Grant delete request :

<Limit GET POST PUT DELETE>
  Allow from all
</Limit>

As you can see the DELETE method(request) has been added to .htaccess

Sign up to request clarification or add additional context in comments.

2 Comments

the route is exist, i am really wondering..... in other page i have exactly same thing and it does work.... just the differnce is i used .Route::resource instead of Route::delete !!
@OsamaMohammed So the problem is probably from the web server .. See the updated answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.