1$table->unsignedBigInteger('user_id');
2$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
1Schema::table('posts', function (Blueprint $table) {
2 $table->unsignedBigInteger('user_id');
3
4 $table->foreign('user_id')->references('id')->on('users');
5});
6OR
7Schema::table('posts', function (Blueprint $table) {
8 $table->foreignId('user_id')->constrained();
9});
1$table->foreign('column_name')->references('id')->on('table_name')->onDelete('cascade');
1Schema::table('posts', function (Blueprint $table) {
2 $table->unsignedBigInteger('user_id');
3
4 $table->foreign('user_id')->references('id')->on('users');
5});
1use Illuminate\Database\Schema\Blueprint;
2use Illuminate\Support\Facades\Schema;
3
4Schema::table('posts', function (Blueprint $table) {
5 $table->unsignedBigInteger('user_id');
6
7 $table->foreign('user_id')->references('id')->on('users');
8});