Hello, i'm trying to understand how to create a new table that has a relation with the users table.
i'm trying something like this but is wrong:
<?php
use Illuminate\Database\Schema\Builder;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return [
'up' => function (Builder $schema) {
if (Schema::hasTable('my_table_name')) {
Schema::drop('my_table_name');
}
$schema->create('my_table_name', function (Blueprint $table) {
$table->bigIncrements('id');
$table->unsignedInteger('user_id');
$table->unsignedInteger('my_prop');
$table->text('other_prop');
$table->timestamps();
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->foreign('my_prop')->references('id')->on('users')->onDelete('cascade');
});
},
'down' => function (Builder $schema) {
$schema->dropIfExists('my_table_name');
},
];
can someone points me into a right direction?