Вот 3 синтаксических способа определения внешнего ключа отношения belongsTo в миграциях. Лично я считаю второй вариант более предпочтительным.
Schema:: create( 'orders', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger( 'user_id');
$table->foreign('user_id')->references( id') ->on('users");
});
// Or
Schema: :create( 'orders', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->constrained();
});
/Or
Schema: :create( 'orders', function (Blueprint $table) {
$table->id();
$table->foreignIdFor (User: :class) ->constrained( ) ;
/
});
👉 @php_lib
