$table->integer('user_id')->unsigned()->nullable();
$table->foreign('user_id')->references('id')->on('users');
Schema::create('articles', function (Blueprint $table) {
$table->increments('id');
$table->string('body');
$table->timestamps();
});
// Add Foreign key
Schema::table('articles', function (Blueprint $table) {
$table->unsignedInteger('user_id');
$table->foreign('user_id')->references('id')-
>on('users')->onDelete('cascade');
});
php artisan make:migration add_paid_to_users_table --table=users
Schema::table() method (as you're accessing an existing table, not creating a new one). And you can add a column like this:public function up()
{
Schema::table('users', function($table) {
$table->integer('paid');
});
}
public function down()
{
Schema::table('users', function($table) {
$table->dropColumn('paid');
});
}
php artisan migrate
Labels: Laravel, Web development