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});
1// Searched, laravel drop foreign column
2Schema::table('users', function (Blueprint $table) {
3 $table->dropColumn(['votes', 'avatar', 'location']);
4});
1public function up()
2{
3 Schema::create('replies', function (Blueprint $table) {
4 $table->bigIncrements('id');
5 $table->text('body');
6 $table->unsignedBigInteger('question_id');
7 $table->integer('user_id')->unsigned();
8 $table->foreign('question_id')->references('id')->on('questions')->onDelete('cascade');
9 $table->timestamps();
10 });
11}
12