From 7bfba072bbc9d8ce3a23868934dc565be6851dc8 Mon Sep 17 00:00:00 2001 From: James Brooks Date: Tue, 18 Jul 2017 22:52:49 +0100 Subject: [PATCH] Create incident_components table --- app/Models/IncidentComponent.php | 76 +++++++++++++++++++ ..._07_18_214718_CreateIncidentComponents.php | 42 ++++++++++ tests/Models/IncidentComponentTest.php | 31 ++++++++ 3 files changed, 149 insertions(+) create mode 100644 app/Models/IncidentComponent.php create mode 100644 database/migrations/2017_07_18_214718_CreateIncidentComponents.php create mode 100644 tests/Models/IncidentComponentTest.php diff --git a/app/Models/IncidentComponent.php b/app/Models/IncidentComponent.php new file mode 100644 index 00000000..55aebcac --- /dev/null +++ b/app/Models/IncidentComponent.php @@ -0,0 +1,76 @@ + + */ +class IncidentComponent extends Model +{ + use ValidatingTrait; + + /** + * The attributes that should be casted to native types. + * + * @var string[] + */ + protected $casts = [ + 'incident_id' => 'int', + 'component_id' => 'int', + ]; + + /** + * The fillable properties. + * + * @var string[] + */ + protected $fillable = [ + 'incident_id', + 'component_id', + ]; + + /** + * The validation rules. + * + * @var string[] + */ + public $rules = [ + 'incident_id' => 'required|int', + 'component_id' => 'required|int', + ]; + + /** + * Get the incident relation. + * + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ + public function incident() + { + return $this->belongsTo(Incident::class); + } + + /** + * Get the component relation. + * + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ + public function component() + { + return $this->belongsTo(Component::class); + } +} diff --git a/database/migrations/2017_07_18_214718_CreateIncidentComponents.php b/database/migrations/2017_07_18_214718_CreateIncidentComponents.php new file mode 100644 index 00000000..eec87f54 --- /dev/null +++ b/database/migrations/2017_07_18_214718_CreateIncidentComponents.php @@ -0,0 +1,42 @@ +increments('id'); + $table->integer('incident_id')->unsigned()->index(); + $table->integer('component_id')->unsigned()->index(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('incident_components'); + } +} diff --git a/tests/Models/IncidentComponentTest.php b/tests/Models/IncidentComponentTest.php new file mode 100644 index 00000000..fd2816fd --- /dev/null +++ b/tests/Models/IncidentComponentTest.php @@ -0,0 +1,31 @@ + + */ +class IncidentComponentTest extends AbstractTestCase +{ + use ValidationTrait; + + public function testValidation() + { + $this->checkRules(new IncidentComponent()); + } +}