Monday, 19 July 2021

Laravel Non-static method Illuminate\Database\Eloquent\Model::update() should not be called statically


Reason:
Sometimes DB updates do not work because we are calling non-static methods statically.



We should change your approach to update the Product. We could possibly follow different ways.



Error Code

Product::update([ 'product_sku' => $product_sku,'product_name' => $product_name);


We are calling to update suddenly after the status product but must need to change it to something like

Product::where('id', $product_id)->update([ 'product_sku' => $product_sku

,'product_name' => $product_name);
or
Product::find($id)
->update([ 'product_sku' => $product_sku,'product_name' => $product_name);

No comments:

Post a Comment

Laravel csrf token mismatch for ajax post request

Error "CSRF Token Mismatch" commonly occurs if tokens do not match in both sessions and sent , and received requests.CSRF token he...