xxxxxxxxxx
Schema::create('users_contact', function (Blueprint $table) {
$table->id();
$table->text('address');
$table->unsignedBigInteger('id');
$table->unsignedBigInteger('contact_no')->nullable();
$table->integer('user_contact_id')->nullable();
$table->string('tag_string');
$table->text('second_email')->nullable();
$table->timestamps();
$table->foreign('user_contact_id')->references('id')->on('users');
});
xxxxxxxxxx
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
xxxxxxxxxx
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddForeignKeyToTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('your_table_name', function (Blueprint $table) {
$table->foreign('foreign_key_column')->references('referenced_column')->on('referenced_table')->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('your_table_name', function (Blueprint $table) {
$table->dropForeign(['foreign_key_column']);
});
}
}