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/Console/Commands/DemoSeederCommand.php b/app/Console/Commands/DemoSeederCommand.php index 4aeb7300..ee5483f2 100644 --- a/app/Console/Commands/DemoSeederCommand.php +++ b/app/Console/Commands/DemoSeederCommand.php @@ -85,6 +85,7 @@ class DemoSeederCommand extends Command return; } + $this->seedUsers(); $this->seedActions(); $this->seedComponentGroups(); $this->seedComponents(); @@ -95,7 +96,6 @@ class DemoSeederCommand extends Command $this->seedSchedules(); $this->seedSettings(); $this->seedSubscribers(); - $this->seedUsers(); $this->info('Database seeded with demo data successfully!'); } @@ -223,6 +223,7 @@ EINCIDENT; 'component_id' => 0, 'visible' => 1, 'stickied' => false, + 'user_id' => 1, 'occurred_at' => Carbon::now(), ], [ @@ -232,6 +233,7 @@ EINCIDENT; 'component_id' => 0, 'visible' => 1, 'stickied' => false, + 'user_id' => 1, 'occurred_at' => Carbon::now(), ], ]; 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/factories/ModelFactory.php b/database/factories/ModelFactory.php index 53bed099..914c70aa 100644 --- a/database/factories/ModelFactory.php +++ b/database/factories/ModelFactory.php @@ -45,6 +45,7 @@ $factory->define(ComponentGroup::class, function ($faker) { $factory->define(Incident::class, function ($faker) { return [ 'name' => $faker->sentence(), + 'user_id' => factory(User::class)->create()->id, 'message' => $faker->paragraph(), 'status' => mt_rand(1, 4), 'visible' => 1, 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'); + }); + } +} diff --git a/resources/lang/en/dashboard.php b/resources/lang/en/dashboard.php index d99fbc61..3707fc05 100644 --- a/resources/lang/en/dashboard.php +++ b/resources/lang/en/dashboard.php @@ -35,6 +35,7 @@ return [ 'failure' => 'Something went wrong updating the incident update', ], ], + 'reported_by' => 'Reported by :user', 'add' => [ 'title' => 'Report an incident', 'success' => 'Incident added.', diff --git a/resources/views/dashboard/incidents/index.blade.php b/resources/views/dashboard/incidents/index.blade.php index 78e62cf4..0f49b862 100644 --- a/resources/views/dashboard/incidents/index.blade.php +++ b/resources/views/dashboard/incidents/index.blade.php @@ -24,7 +24,10 @@
{{ Str::words($incident->message, 5) }}
+{{ Str::words($incident->message, 5) }}
+ @endif + @if ($incident->user) +— {{ trans('dashboard.incidents.reported_by', ['user' => $incident->user->username]) }}
@endif