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});
1Schema::table('posts', function (Blueprint $table) {
2 $table->dropForeign(['category_id']);
3});
1// Searched, laravel drop foreign column
2Schema::table('users', function (Blueprint $table) {
3 $table->dropColumn(['votes', 'avatar', 'location']);
4});
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});
1Schema::table('admins', function (Blueprint $table) { $table->dropForeign('admins_post_id_foreign'); $table->dropColumn('post_id');});