Skip to content
Advertisement

Laravel Update not working

I have table called admins and model called Admin.

When i try to update the records it fails every time with one field.

$admindetail = Admin::find($id);
$admindetail->fill(['is_delete'=>1])->save();

Above code is not updating record in DB. datatype for is_delete is tinyint.

If i update name field it works with the same code like

$admindetail = Admin::find($id);
$admindetail->fill(['name'=>'abc'])->save();

Can you help me why first code is not working.

Advertisement

Answer

Model use to interact with table so all attributes which you need to store in DB you should need to define in your model as your Admin model should look like

   <?php

namespace App;

use IlluminateDatabaseEloquentModel;

class Admin extends Model
{
    protected $fillable = ['name', 'is_delete'];
}

You missing is_delete from your Model code.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement