migrateion laravel edit code example

Example 1: migrations required field laravel

$table->string('foo')->nullable(false)->change();

Example 2: laravel migration constrained

Schema::table('posts', function (Blueprint $table) {
    $table->foreignId('user_id')->constrained();
});

/* The foreignId method is an alias for unsignedBigInteger while the
 * constrained method will use conventions to determine the table and
 * column name being referenced. If your table name does not match
 * Laravel's conventions, you may specify the table name by passing it
 * as an argument to the constrained method:
*/

Schema::table('posts', function (Blueprint $table) {
    $table->foreignId('user_id')->constrained('users');
});

Tags:

Misc Example