diff --git a/app/Models/IncidentComponent.php b/app/Models/IncidentComponent.php new file mode 100644 index 000000000000..13218d152062 --- /dev/null +++ b/app/Models/IncidentComponent.php @@ -0,0 +1,78 @@ + + */ +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', + 'status_id' => 'int', + ]; + + /** + * The fillable properties. + * + * @var string[] + */ + protected $fillable = [ + 'incident_id', + 'component_id', + 'status_id', + ]; + + /** + * The validation rules. + * + * @var string[] + */ + public $rules = [ + 'incident_id' => 'required|int', + 'component_id' => 'required|int', + 'status_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..f1926441c275 --- /dev/null +++ b/database/migrations/2017_07_18_214718_CreateIncidentComponents.php @@ -0,0 +1,43 @@ +increments('id'); + $table->integer('incident_id')->unsigned()->index(); + $table->integer('component_id')->unsigned()->index(); + $table->integer('status_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()); + } +}