Skip to content
Permalink
Browse files

Episode 28 Complete

  • Loading branch information...
JeffreyWay committed Feb 14, 2019
1 parent ee70299 commit ad4611794b0e602e5cf47d165e7af54bb93d2d46
@@ -31,4 +31,14 @@ public function subject()
{
return $this->morphTo();
}
/**
* Get the user who triggered the activity.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function user()
{
return $this->belongsTo(User::class);
}
}
@@ -62,6 +62,7 @@ protected static function recordableEvents()
public function recordActivity($description)
{
$this->activity()->create([
'user_id' => ($this->project ?? $this)->owner->id,
'description' => $description,
'changes' => $this->activityChanges(),
'project_id' => class_basename($this) === 'Project' ? $this->id : $this->project_id
@@ -15,12 +15,14 @@ public function up()
{
Schema::create('activities', function (Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('user_id');
$table->unsignedInteger('project_id');
$table->nullableMorphs('subject');
$table->string('description');
$table->text('changes')->nullable();
$table->timestamps();
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->foreign('project_id')->references('id')->on('projects')->onDelete('cascade');
});
}
@@ -1 +1 @@
You completed "{{ $activity->subject->body }}"
{{ $activity->user->name }} completed "{{ $activity->subject->body }}"
@@ -1 +1 @@
You created the project
{{ $activity->user->name }} created the project
@@ -1 +1 @@
You created "{{ $activity->subject->body }}"
{{ $activity->user->name }} created "{{ $activity->subject->body }}"
@@ -1 +1 @@
You incompleted "{{ $activity->subject->body }}"
{{ $activity->user->name }} incompleted "{{ $activity->subject->body }}"
@@ -1 +1,5 @@
You updated the project
@if (count($activity->changes['after']) == 1)
{{ $activity->user->name }} updated the {{ key($activity->changes['after']) }} of the project
@else
{{ $activity->user->name }} updated the project
@endif
@@ -0,0 +1,25 @@
<?php
namespace Tests\Unit;
use App\Activity;
use App\Project;
use App\User;
use Facades\Tests\Setup\ProjectFactory;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class ActivityTest extends TestCase
{
use RefreshDatabase;
/** @test */
function it_has_a_user()
{
$user = $this->signIn();
$project = ProjectFactory::ownedBy($user)->create();
$this->assertEquals($user->id, $project->activity->first()->user->id);
}
}

0 comments on commit ad46117

Please sign in to comment.
You can’t perform that action at this time.