Search code examples
laravelschedule

Laravel schedule: creating new row in a table automatically


(Laravel framework) I'm trying to create new row automatically in a table using schedule inside the handle function but it's not adding the row to the table:

public function handle()
{
    Reserved::create([
              'book_id'=>1,
              'user_id'=>1
    ]);
}

the schedule is working when I try other things like deleting a row or sending emails... What can I do?


Solution

  • You probably haven't added the $fillable property to your Reserved model class. This prevents the create method from storing a new instance.

    See Documentation: https://laravel.com/docs/9.x/eloquent#mass-assignment