Holiday Model
For understanding, how the model code works, please refer to country model or company model
Below code create holiday model & migration files.
php artisan make:model Holiday -m
Since are working on name, startDate, endDate, fullDay, company_id, we add them to Model and Migration files.
Model class
Replace model class with below code.
Note: Please use the copy button to copy the source code.
We need to include the following import statement(s)
use Illuminate\Database\Eloquent\SoftDeletes;
class Holiday extends Model
{
use HasFactory;
use SoftDeletes;
protected $fillable = [
'name',
'startDate',
'endDate',
'fullDay',
'company_id',
];
}
Migration class
Replace the up() and down() methods with the code below.
public function up()
{
Schema::create('holidays', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->date('startDate');
$table->date('endDate');
$table->boolean('fullDay')->default(0);
$table->foreignId('company_id')->constrained();
$table->softDeletes();
$table->timestamps();
});
}
public function down()
{
Schema::dropIfExists('holidays');
}
To create/update the table to database, we need to run artisan migrate command
php artisan migrate