Leave Type Model
For understanding, how the model code works, please refer to country model or company model
Below code create leave type model & migration files.
php artisan make:model LeaveType -m
Since we are working on name, allowNegativeApplication, needCertificate, company_id, cycleMonth, we add them to Model and Migration files. allowNegativeApplication
indicates if a user allowed to go beyond entitlement days. needCertificate
is to tell the user if they need to upload the document as a supplement to leave application. Finally cycleMonth
is a cut-off month for entitlement month for a year.
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 LeaveType extends Model
{
use HasFactory;
use SoftDeletes;
protected $fillable = [
'name',
'allowNegativeApplication',
'needCertificate',
'company_id',
'cycleMonth',
];
}
Migration class
Replace the up() and down() methods with the code below.
public function up()
{
Schema::create('leave_types', function (Blueprint $table) {
$table->id();
$table->timestamps();
$table->text('name');
$table->integer('cycleMonth');
$table->boolean('allowNegativeApplication')->default(0);
$table->boolean('needCertificate')->default(0);
$table->foreignId('company_id')->constrained();
$table->softDeletes();
});
}
public function down()
{
Schema::dropIfExists('leave_types');
}
To create/update the table to database, we need to run artisan migrate command
php artisan migrate