0

laravel 5.8 and php 7.4

this only happen after I deploy the project on the server

I made delete request like this

enter image description here

response

enter image description here


web.php

Route::group(['prefix' => 'admin', 'middleware' => 'auth', /*'middleware' => ['auth','administrator'] ,*/ 'namespace' => 'admin', 'as' => 'admin.'], function () {
    Route::resource('/sellers', 'SellerController');

});

SellerController.php

class SellerController extends Controller
{
 public function show(Request $request, $id)
    {

        return ['msg' => 'it is show method '];
    }
   public function destroy(Request $request, $id)
    {
        if ($request->ajax()) {
            if ($request->user()->cannot('destroy', Seller::class)) {
                return ['error' => 'unauthorized'];
            }
            try {
                $teams = DB::table('team_user')->where('user_id', $id)->delete();
                $deleted = $this->model_instance::findOrFail($id);
                $deleted->delete();
                $deleted->name = " [archived]  $deleted->name #$id";
                $deleted->save();

                if ($deleted) {
                    $log_message = trans('sellers.delete_log') . '#' . $id;
                    logActivity($log_message);
                    return response()->json(['status' => 'success', 'message' => 'deleted_successfully']);
                } else {
                    return response()->json(['status' => 'fail', 'message' => 'fail_while_delete']);
                }
            } catch (\Exception $ex) {
                DB::rollBack();
                dd($ex->getMessage());
                Log::error($ex->getMessage());
                return redirect()->route($this->index_route)->with('error', $this->error_message);
            }
        }
        return redirect()->route($this->index_route);
    }

}

in my local server it works fine

  • Are you running `php artisan route:cache`? – matiaslauriti Feb 18 '23 at 04:24
  • @matiaslauriti I don't know because the first time this issue shows I did run a lot of cache commands from the internet, but anyway, this project was on the cPanel before I download it and make some edits, and then upload it again – Mohammad ْAl Hallaq Feb 18 '23 at 04:38

1 Answers1

0

You must pass _method with your API call, like this. enter image description here

Dasun Tharanga
  • 163
  • 1
  • 11
  • yes this was part of the answer in my case there 2 issues 1. `delete request` not working after deploying the project, so tried `post request` with `_method: "delete"` 2. the project was caching things so when I edit and try it failed because actually nothing changed, and because of that the debugging process was really hard and made me confused, so after I noticed that I run `php artisan view:cache` and `php artisan route:cache` and `php artisan config:cache` each time I make edit on the server, then used your solution with post request not delete request , this bug fixed ` – Mohammad ْAl Hallaq Feb 19 '23 at 01:06