Leave Entitlement Model
For understanding, how the model code works, please refer to country model or company model
Below code create leave entitlement model & migration files.
php artisan make:model LeaveEntitlement -m
Since we are working on entitlement, user_id, leave_type_id, year fields/properties, we add them to Model and Migration files. Entitlement is number of day a person is allowed to take leave for a given leave type (e.g. annual leave) and which year.
Model class
Replace model class with below code.
Note: Please use the copy button to copy the source code.
class LeaveEntitlement extends Model
{
use HasFactory;
protected $fillable = [
'entitlement',
'user_id',
'leave_type_id',
'year',
];
}
Migration class
Replace the up() and down() methods with the code below.
public function up()
{
Schema::create('leave_entitlements', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->constrained();
$table->integer('entitlement');
$table->integer('year');
$table->foreignId('leave_type_id')->constrained();
$table->timestamps();
});
}
public function down()
{
Schema::dropIfExists('leave_entitlements');
}
To create/update the table to database, we need to run artisan migrate command
php artisan migrate