Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Database migration for laravel for employees table

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration


{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('employees', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->date('birth_date')->nullable();
$table->date('join_date')->nullable();
$table->string('contact_number')->nullable();
$table->string('contact_person')->nullable();
$table->string('address')->nullable();
$table->string('email')->nullable();
$table->string('image')->nullable(); // Assuming you will store the image path
$table->unsignedBigInteger('department_id')->nullable();
$table->unsignedBigInteger('designation_id')->nullable();
$table->unsignedBigInteger('created_by')->nullable();
$table->unsignedBigInteger('updated_by')->nullable();
$table->unsignedBigInteger('deleted_by')->nullable();
$table->softDeletes();
$table->timestamps();

$table->foreign('department_id')->references('id')->on('departments')-
>onDelete('cascade');
$table->foreign('designation_id')->references('id')->on('designations')-
>onDelete('cascade');
});

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('employees');
}
};

You might also like