database/migrations/2021_05_06_132303_create_orders_table.php
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateOrdersTable extends Migration
{
public function up(): void
{
Schema::create('orders', function (Blueprint $table) {
$table->bigIncrements('id');
$table->foreignId('user_id')->nullable();
$table->unsignedSmallInteger('status');
$table->unsignedInteger('total')->default(0);
$table->unsignedInteger('subtotal')->default(0);
$table->unsignedInteger('tax')->default(0);
$table->timestamps();
$table->index('user_id');
$table->foreign('user_id')->on('users')->references('id');
});
}
public function down(): void
{
Schema::dropIfExists('orders');
}
}