Skip to content

Instantly share code, notes, and snippets.

@djaiss
Created August 20, 2020 19:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djaiss/616f57acabe2352d14d40cecccf5ce04 to your computer and use it in GitHub Desktop.
Save djaiss/616f57acabe2352d14d40cecccf5ce04 to your computer and use it in GitHub Desktop.
Example of `is_dummy` field in the database
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateHardwareTable extends Migration
{
/**
* Run the migrations.
*/
public function up()
{
// necessary for SQLlite
Schema::enableForeignKeyConstraints();
Schema::create('hardware', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('company_id');
$table->unsignedBigInteger('employee_id')->nullable();
$table->string('name');
$table->string('serial_number')->nullable();
$table->boolean('is_dummy')->default(false);
$table->timestamps();
$table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade');
$table->foreign('employee_id')->references('id')->on('employees')->onDelete('set null');
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment