Leave Application Document Model

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

Below code create leave application document model & migration files.

php artisan make:model LeaveApplicationDocument -m

Since are working on name, file, leave_application_id, mime' fields/properties, we add them to Model and Migration files. File hold the BLOB (actual file content) in the database and mime indicate type of file (e.g. PDF);

Model class

Replace model class with below code.

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

class LeaveApplicationDocument extends Model { use HasFactory; protected $fillable = [ 'name', 'file', 'leave_application_id', 'mime', ]; }
Migration class

Remember to add use Illuminate\Support\Facades\DB; to migration file before running migrate command

We also add file as MEDIUMBLOB file type by running ALTER table statement. The binary Laravel which will translate to BLOB might not be enough field length.

public function up() { Schema::create('leave_application_documents', function (Blueprint $table) { $table->id(); $table->string('name'); $table->string('mime'); $table->foreignId('leave_application_id')->constrained(); $table->timestamps(); }); DB::statement("ALTER TABLE leave_application_documents ADD file MEDIUMBLOB"); } public function down() { Schema::dropIfExists('leave_application_documents'); }

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

php artisan migrate