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('users', function (Blueprint $table) {
2 $table->string('name', 50)->nullable()->change();
3});
1// To drop a column, use the dropColumn method on the schema builder.
2// Before dropping columns from a SQLite database, you will need to add
3// the doctrine/dbal dependency to your composer.json file and run the
4// composer update command in your terminal to install the library:
5
6Schema::table('users', function (Blueprint $table) {
7 $table->dropColumn('votes');
8});
1php artisan make:migration add_votes_to_users_table --table=users
2
3php artisan make:migration create_users_table --create=users
1php artisan make:migration change_sometable_in_finance_table --table=finance
2
3public function up()
4{
5 Schema::table('sometable', function (Blueprint $table) {
6 $table->text('text')->change();
7 });
8}
9
1composer require doctrine/dbal
2
3public function up()
4{
5 Schema::table('sometable', function (Blueprint $table) {
6 $table->text('text')->change();
7 });
8}