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.
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 Illuminate\Database\Eloquent\Model;
class Admin extends Model
{
protected $fillable = ['name', 'is_delete'];
}
You missing is_delete
from your Model code.
Instead of passing value as array, you could try the code below:
$admindetail = Admin::find($id);
if(!$admindetail)
{
$admindetail->is_delete=1;
$admindetail->save();
}
You should check your fillable in your model like this:
protected $fillable = [
'name',
'is_delete'
];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With