Issues (56)

app/Observers/TaskObserver.php (4 issues)

1
<?php
2
3
namespace App\Observers;
4
5
use App\Task;
6
use App\TaskEvent;
7
use App\User;
8
use Carbon\Carbon;
9
10
/**
11
 * Created by PhpStorm.
12
 * User: quim
13
 * Date: 15/02/18
14
 * Time: 21:13
15
 */
16
17
class TaskObserver{
18
19
20
    /**
21
     * @param Task $task
22
     */
23
    public function created(Task $task)
24
    {
25
26
        TaskEvent::create([
27
28
            'time' => Carbon::now(),
29
            'type' => 'created',
30
            'task_name' => $task->name,
31
            'user_name' => $task->user->name,
0 ignored issues
show
Bug Best Practice introduced by
The property name does not exist on App\User. Since you implemented __get, consider adding a @property annotation.
Loading history...
32
            'task' => json_encode($task)
33
34
35
        ]);
36
37
    }
38
39
    public function updated(Task $task)
40
    {
41
        TaskEvent::create([
42
            'time' => Carbon::now(),
43
            'task_name' => $task->name,
44
            'user_name' => User::findOrFail($task->user_id)->name,
0 ignored issues
show
Bug Best Practice introduced by
The property name does not exist on App\User. Since you implemented __get, consider adding a @property annotation.
Loading history...
45
            'type' => 'updated',
46
            'task' => json_encode($task)
47
        ]);
48
    }
49
50
    public function saved(Task $task)
51
    {
52
        TaskEvent::create([
53
            'time' => Carbon::now(),
54
            'task_name' => $task->name,
55
            'user_name' => User::findOrFail($task->user_id)->name,
0 ignored issues
show
Bug Best Practice introduced by
The property name does not exist on App\User. Since you implemented __get, consider adding a @property annotation.
Loading history...
56
            'type' => 'saved',
57
            'task' => json_encode($task)
58
        ]);
59
    }
60
61
    public function deleted(Task $task)
62
    {
63
        TaskEvent::create([
64
            'time' => Carbon::now(),
65
            'task_name' => $task->name,
66
            'user_name' => User::findOrFail($task->user_id)->name,
0 ignored issues
show
Bug Best Practice introduced by
The property name does not exist on App\User. Since you implemented __get, consider adding a @property annotation.
Loading history...
67
            'type' => 'deleted',
68
            'task' => json_encode($task)
69
70
        ]);
71
    }
72
}