Try running both versions with pretend mode, to see the query
php artisan migrate --pretend
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
hello, i faced a little issue where the row couldn't get deleted, i know it seems beginner likely, but i want to understand the issue behind it, and why the order of the methods is important when we declare a foreign key in a migration the correct way based on the documentation:
$table->foreignId('user_id')
->constrained() // 2nd
->onUpdate('cascade')
->onDelete('cascade');
How to trigger the mistake:
$table->foreignId('user_id')
->onUpdate('cascade')
->onDelete('cascade');
->constrained() // last
so my question is why the constrained order is critical, because if i create a many to many relationship with the user for example, when i delete the user, the rest won't cascade. thank you in advance
Please or to participate in this conversation.