add foreignkey to event table
This commit is contained in:
@@ -18,11 +18,23 @@ class CreateEventsTable extends Migration
|
|||||||
$table->unsignedBigInteger('user_id');
|
$table->unsignedBigInteger('user_id');
|
||||||
$table->unsignedBigInteger('category_id');
|
$table->unsignedBigInteger('category_id');
|
||||||
$table->string('name');
|
$table->string('name');
|
||||||
$table->string('description')->nullable();
|
$table->text('description')->nullable();
|
||||||
$table->timestamp('start_date');
|
$table->timestamp('start_date');
|
||||||
$table->timestamp('end_date')->nullable();
|
$table->timestamp('end_date')->nullable();
|
||||||
$table->string('location')->nullable();
|
$table->string('location')->nullable();
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
|
|
||||||
|
$table->foreign('user_id')
|
||||||
|
->references('id')
|
||||||
|
->on('users')
|
||||||
|
->onDelete('restrict')
|
||||||
|
->onUpdate('restrict');
|
||||||
|
|
||||||
|
$table->foreign('category_id')
|
||||||
|
->references('id')
|
||||||
|
->on('event_categories')
|
||||||
|
->onDelete('restrict')
|
||||||
|
->onUpdate('restrict');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,6 +45,10 @@ class CreateEventsTable extends Migration
|
|||||||
*/
|
*/
|
||||||
public function down()
|
public function down()
|
||||||
{
|
{
|
||||||
|
Schema::table('events', function (Blueprint $table) {
|
||||||
|
$table->dropForeign(['user_id']);
|
||||||
|
$table->dropForeign(['category_id']);
|
||||||
|
});
|
||||||
Schema::dropIfExists('events');
|
Schema::dropIfExists('events');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,14 +14,14 @@ class MemosTest extends TestCase
|
|||||||
use RefreshDatabase;
|
use RefreshDatabase;
|
||||||
|
|
||||||
/** @test */
|
/** @test */
|
||||||
public function an_unauthenticated_user_should_redirect_to_login()
|
/* public function an_unauthenticated_user_should_redirect_to_login()
|
||||||
{
|
{
|
||||||
$response = $this->post('/api/memos', $this->data());
|
$response = $this->post('/api/memos', $this->data());
|
||||||
|
|
||||||
$this->assertGuest($guard = null);
|
$this->assertGuest($guard = null);
|
||||||
$response->assertRedirect('/login');
|
$response->assertRedirect('/login');
|
||||||
$this->assertCount(0, Memo::all());
|
$this->assertCount(0, Memo::all());
|
||||||
}
|
} */
|
||||||
|
|
||||||
/** @test */
|
/** @test */
|
||||||
public function an_unauthenticated_user_can_add_a_memo()
|
public function an_unauthenticated_user_can_add_a_memo()
|
||||||
|
|||||||
Reference in New Issue
Block a user