laraveltinker

How to update data in the database using artisan Tinker


First,I call artisan tinker using the command below

$ php artisan tinker


Then, I plan to get all of the model in Admin to update the name as "admin", then I save the update by using command below

$admin = App\Admin::get()->name="admin"->save()

//Admin is my model
//name is the table structure of Admin table
//then I save it with save()


However, it pop out an error as shown below :-

PHP Error: Call to a member function save() on string in Psy Shell code on line 1


Solution

  • With update method.

    $admin = App\Admin::query()->update(['name' => 'admin']);

    In Admin model:

    protected $fillable = 'name';