mardi 20 octobre 2020

Method update does not exist in Laravel

It is very simple code to update an existing entry. save() is working perfectly. But update is not working. Here is my code:

Route::post('toggleFavourite',function(){
    try{
        $data = Request::all();
        extract($data);
        $favourite = \ItScholarBd\Api\Models\Favourite::where(['user_id'=> $user_id,'shop_id'=> $shop_id])->get();
        if(empty($favourite)){
            $favourite = new \ItScholarBd\Api\Models\Favourite;
            $favourite->user_id = $user_id;
            $favourite->shop_id = $shop_id;
            $favourite->status  = $status;
            $favourite->save();
        }else{
            $favourite->status  = $status;
            $favourite->update();
        }
        return response()->json(['status' =>1, 'data' => $favourite], 200); 
    }
    catch (Exception $ex) {
        return response()->json(['status'=>0, 'status_text' => $ex->getMessage()], 500);

    }
});

I am getting the following response:

{"status":0,"status_text":"Method update does not exist."}


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/34gIGPQ
via IFTTT

Aucun commentaire:

Enregistrer un commentaire