diff --git a/app/Bus/Handlers/Commands/Incident/CreateIncidentCommandHandler.php b/app/Bus/Handlers/Commands/Incident/CreateIncidentCommandHandler.php index 4504d905..0e14a298 100644 --- a/app/Bus/Handlers/Commands/Incident/CreateIncidentCommandHandler.php +++ b/app/Bus/Handlers/Commands/Incident/CreateIncidentCommandHandler.php @@ -70,6 +70,7 @@ class CreateIncidentCommandHandler public function handle(CreateIncidentCommand $command) { $data = [ + 'user_id' => $this->auth->user()->id, 'name' => $command->name, 'status' => $command->status, 'visible' => $command->visible, diff --git a/app/Models/Incident.php b/app/Models/Incident.php index 728c6085..d426aa41 100644 --- a/app/Models/Incident.php +++ b/app/Models/Incident.php @@ -74,6 +74,7 @@ class Incident extends Model implements HasPresenter * @var string[] */ protected $casts = [ + 'user_id' => 'int', 'visible' => 'int', 'stickied' => 'bool', 'occurred_at' => 'datetime', @@ -86,6 +87,7 @@ class Incident extends Model implements HasPresenter * @var string[] */ protected $fillable = [ + 'user_id', 'component_id', 'name', 'status', @@ -103,6 +105,7 @@ class Incident extends Model implements HasPresenter * @var string[] */ public $rules = [ + 'user_id' => 'required|int', 'component_id' => 'nullable|int', 'name' => 'required|string', 'status' => 'required|int', @@ -118,6 +121,7 @@ class Incident extends Model implements HasPresenter */ protected $searchable = [ 'id', + 'user_id', 'component_id', 'name', 'status', @@ -132,6 +136,7 @@ class Incident extends Model implements HasPresenter */ protected $sortable = [ 'id', + 'user_id', 'name', 'status', 'visible', @@ -180,6 +185,16 @@ class Incident extends Model implements HasPresenter return $this->hasMany(IncidentUpdate::class)->orderBy('created_at', 'desc'); } + /** + * Get the user relation. + * + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ + public function user() + { + return $this->belongsTo(User::class); + } + /** * Finds all visible incidents. * diff --git a/app/Models/IncidentUpdate.php b/app/Models/IncidentUpdate.php index 207e129e..a6474661 100644 --- a/app/Models/IncidentUpdate.php +++ b/app/Models/IncidentUpdate.php @@ -83,6 +83,16 @@ class IncidentUpdate extends Model implements HasPresenter return $this->belongsTo(Incident::class); } + /** + * Get the user relation. + * + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ + public function user() + { + return $this->belongsTo(User::class); + } + /** * Get the presenter class. * diff --git a/database/migrations/2017_09_14_180434_AlterIncidentsAddUserId.php b/database/migrations/2017_09_14_180434_AlterIncidentsAddUserId.php new file mode 100644 index 00000000..55e42b6a --- /dev/null +++ b/database/migrations/2017_09_14_180434_AlterIncidentsAddUserId.php @@ -0,0 +1,41 @@ +integer('user_id')->unsigned()->nullable()->default(null)->index()->after('id'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('incidents', function (Blueprint $table) { + $table->dropColumn('user_id'); + }); + } +}