Leave Application Model

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

Below code create leave application model & migration files.

php artisan make:model LeaveApplication -m

Since we are working startDate, endDate, name, full day, user_id, leave_type_id, noOfDayApplied, noOfWorkingDay, noOfPublicHoliday, noOfDayDeduct, leaveStatus, needCertificate fields/properties, we add them to Model and Migration files. 'noOfDayApplied' is days difference (inclusive) between 'startDate' and 'endDate'. 'noOfWorkingDay' is a number of the working days occurs between 'startDate' and 'endDate', whereas 'noOfPublicHoliday' is a number of public holidays occur during that period. 

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 LeaveApplication extends Model { use HasFactory; use SoftDeletes; protected $fillable = [ 'startDate', 'endDate', 'name', 'fullDay', 'user_id', 'leave_type_id', 'noOfDayApplied', 'noOfWorkingDay', 'noOfPublicHoliday', 'noOfDayDeduct', 'leaveStatus', 'needCertificate', ]; }
Migration class

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

We can define the default value of any field/property by using ->default(0)

public function up() { Schema::create('leave_applications', function (Blueprint $table) { $table->id(); $table->date('startDate'); $table->date('endDate'); $table->string('name'); $table->boolean('fullDay')->default(1); $table->integer('noOfDayApplied'); $table->integer('noOfWorkingDay'); $table->integer('noOfPublicHoliday'); $table->integer('noOfDayDeduct'); $table->integer('leaveStatus')->default(0);; $table->foreignId('user_id')->constrained(); $table->foreignId('leave_type_id')->constrained(); $table->boolean('needCertificate')->default(0); $table->softDeletes(); $table->timestamps(); }); } public function down() { Schema::dropIfExists('leave_applications'); } }

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

php artisan migrate