vendredi 17 février 2023

destroy doesn't invoked, instead it executed show method in controller

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



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire