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});
1public function up()
2{
3 Schema::create('replies', function (Blueprint $table) {
4 $table->bigIncrements('id');
5 $table->text('body');
6 $table->unsignedBigInteger('question_id');
7 $table->integer('user_id')->unsigned();
8 $table->foreign('question_id')->references('id')->on('questions')->onDelete('cascade');
9 $table->timestamps();
10 });
11}
12
1// in laravel if error of missing pdomysql driver issue the command
2// composer require doctrine/dbal
3DB::connection()->getDoctrineColumn($table_name, $field_name)->getType()->getName()
1Schema::table('portfolios', function (Blueprint $table) {
2 $table->string('filter_alias');
3 $table->foreign('filter_alias')->cascadeOnDelete()->references('alias')->on('filters');
4 });