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// use the make:migration Artisan command to generate a database migration
2php artisan make:migration create_flights_table
3
4// use --create to indicate whether the migration will be creating a new table
5php artisan make:migration create_flights_table --create=flights
6
7// use --table to indicate the table name
8php artisan make:migration add_destination_to_flights_table --table=flights
1# If you would like to generate a database migration when you
2# generate the model, you may use the --migration or -m option:
3
4php artisan make:model Flight --migration
5php artisan make:model Flight -m
1php artisan make:migration create_users_table --create=users
2
3php artisan make:migration add_votes_to_users_table --table=users