Event Model

For understanding, how the model code works, please refer to country model or company model

Below code create event model & migration files.

php artisan make:model Event -m

Since we are working on title, start , end, wholeDay, user_id property/fields, we add them to Model and Migration file.

Model class

Replace model class with below code.

Note: Please use the copy button to copy the source code.

class Event extends Model { use HasFactory; protected $fillable = [ 'title', 'start', 'end', 'wholeDay', 'user_id' ]; }
Migration class

Replace the up() and down() methods with the code below.

public function up() { Schema::create('events', function (Blueprint $table) { $table->id(); $table->string('title'); $table->dateTime('start'); $table->dateTime('end'); $table->boolean('wholeDay')->default(0); $table->foreignId('user_id')->constrained(); $table->timestamps(); }); } public function down() { Schema::dropIfExists('events'); }

To create/update the table to database, we need to run artisan migrate command

php artisan migrate