From 7bfba072bbc9d8ce3a23868934dc565be6851dc8 Mon Sep 17 00:00:00 2001 From: James Brooks Date: Tue, 18 Jul 2017 22:52:49 +0100 Subject: [PATCH 1/3] 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 000000000000..55aebcac66c0 --- /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 000000000000..eec87f54b46d --- /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 000000000000..fd2816fdfc32 --- /dev/null +++ b/tests/Models/IncidentComponentTest.php @@ -0,0 +1,31 @@ + + */ +class IncidentComponentTest extends AbstractTestCase +{ + use ValidationTrait; + + public function testValidation() + { + $this->checkRules(new IncidentComponent()); + } +} From 188eb00ca8ac8612299a2ce106aade2e65168d9f Mon Sep 17 00:00:00 2001 From: James Brooks Date: Tue, 18 Jul 2017 21:52:51 +0000 Subject: [PATCH 2/3] Apply fixes from StyleCI [ci skip] [skip ci] --- app/Models/IncidentComponent.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/Models/IncidentComponent.php b/app/Models/IncidentComponent.php index 55aebcac66c0..76b36e7fe6b3 100644 --- a/app/Models/IncidentComponent.php +++ b/app/Models/IncidentComponent.php @@ -13,7 +13,6 @@ use AltThree\Validator\ValidatingTrait; use Illuminate\Database\Eloquent\Model; -use Illuminate\Support\Str; /** * This is the incident component model class. From 7622a8f47490a3d611b0dd7602e89c1fecac4f93 Mon Sep 17 00:00:00 2001 From: James Brooks Date: Tue, 25 Jul 2017 14:40:43 -0400 Subject: [PATCH 3/3] Add status_id column --- app/Models/IncidentComponent.php | 3 +++ .../migrations/2017_07_18_214718_CreateIncidentComponents.php | 1 + 2 files changed, 4 insertions(+) diff --git a/app/Models/IncidentComponent.php b/app/Models/IncidentComponent.php index 76b36e7fe6b3..13218d152062 100644 --- a/app/Models/IncidentComponent.php +++ b/app/Models/IncidentComponent.php @@ -31,6 +31,7 @@ class IncidentComponent extends Model protected $casts = [ 'incident_id' => 'int', 'component_id' => 'int', + 'status_id' => 'int', ]; /** @@ -41,6 +42,7 @@ class IncidentComponent extends Model protected $fillable = [ 'incident_id', 'component_id', + 'status_id', ]; /** @@ -51,6 +53,7 @@ class IncidentComponent extends Model public $rules = [ 'incident_id' => 'required|int', 'component_id' => 'required|int', + 'status_id' => 'required|int', ]; /** diff --git a/database/migrations/2017_07_18_214718_CreateIncidentComponents.php b/database/migrations/2017_07_18_214718_CreateIncidentComponents.php index eec87f54b46d..f1926441c275 100644 --- a/database/migrations/2017_07_18_214718_CreateIncidentComponents.php +++ b/database/migrations/2017_07_18_214718_CreateIncidentComponents.php @@ -26,6 +26,7 @@ public function up() $table->increments('id'); $table->integer('incident_id')->unsigned()->index(); $table->integer('component_id')->unsigned()->index(); + $table->integer('status_id')->unsigned()->index(); $table->timestamps(); }); }