<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
toramanlis / laravel-implicit-migrations example snippets
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class OrderItem extends Model
{
/**
* @Column(unsigned: true)
*/
public int $product_id;
}
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use App\Models\OrderItem as Source;
return new class extends Migration
{
public const TABLE_NAME = 'order_items';
public function getSource(): string
{
return Source::class;
}
public function tableUp(Blueprint $table): void
{
$table->id();
$table->integer('product_id')->unsigned();
$table->timestamps();
}
public function up(): void
{
Schema::create(static::TABLE_NAME, function (Blueprint $table) {
$this->tableUp($table);
});
}
public function down(): void
{
Schema::drop(static::TABLE_NAME);
}
};
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Toramanlis\ImplicitMigrations\Attributes\Column;
class OrderItem extends Model
{
#[Column(unsigned: true)]
public int $product_id;
}
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class OrderItem extends Model
{
/**
* @Column(unsigned: true)
*/
public int $product_id;
public int $order_id;
}
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use App\Models\OrderItem as Source;
return new class extends Migration
{
public const TABLE_NAME = 'order_items';
public function getSource(): string
{
return Source::class;
}
public function tableUp(Blueprint $table): void
{
$table->integer('order_id');
}
public function tableDown(Blueprint $table): void
{
$table->dropColumn('order_id');
}
public function up(): void
{
Schema::table(static::TABLE_NAME, function (Blueprint $table) {
$this->tableUp($table);
});
}
public function down(): void
{
Schema::table(static::TABLE_NAME, function (Blueprint $table) {
$this->tableDown($table);
});
}
};
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.