1Schema::table('posts', function (Blueprint $table) {
2 $table->foreignId('user_id')->constrained();
3});
4
5/* The foreignId method is an alias for unsignedBigInteger while the
6 * constrained method will use conventions to determine the table and
7 * column name being referenced. If your table name does not match
8 * Laravel's conventions, you may specify the table name by passing it
9 * as an argument to the constrained method:
10*/
11
12Schema::table('posts', function (Blueprint $table) {
13 $table->foreignId('user_id')->constrained('users');
14});