Replies: 2 comments 4 replies
-
|
Migrations should ideally be without dependencies and side effects. Having the model class there is a bad idea, because the migration class can get out of date and not be runnable anymore when the model is deleted. |
Beta Was this translation helpful? Give feedback.
4 replies
-
|
In the meantime, I've created a few macros in a Provider in case anyone wants to test the concept - BlueprintMacroProvider.php. Add to Example could be something like this: public function up(): void
{
Schema::create('post_tag', function (Blueprint $table) {
$table->foreignIdFor(Post::class)->constrained()->cascadeOnDelete();
$table->foreignIdFor(Tag::class)->constrained()->cascadeOnDelete();
$table->primaryFor([Post::class, Tag::class]);
$table->indexFor(Post::class);
});
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
When defining pivot table migrations, foreignIdFor(Model::class) gives a clean, model-aware syntax.
There's no equivalent for composite primary keys, which means you end up mixing styles:
Proposed implementation:
Beta Was this translation helpful? Give feedback.
All reactions