| Total Complexity | 8 |
| Total Lines | 67 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 11 | class TasksObserver |
||
| 12 | { |
||
| 13 | /** |
||
| 14 | * Listen to the Task created event. |
||
| 15 | * |
||
| 16 | * @param \App\Task $task |
||
| 17 | * |
||
| 18 | * @return void |
||
| 19 | */ |
||
| 20 | public function created(Task $task) |
||
| 21 | { |
||
| 22 | if (Auth::check()) { |
||
| 23 | $username = Auth::user()->name; |
||
|
|
|||
| 24 | } else { |
||
| 25 | $username = User::findOrFail($task->user_id)->name; |
||
| 26 | } |
||
| 27 | TaskEvent::create([ |
||
| 28 | 'time' => Carbon::now(), |
||
| 29 | 'task_name' => $task->name, |
||
| 30 | 'user_name' => $username, |
||
| 31 | 'type' => 'created', |
||
| 32 | ]); |
||
| 33 | } |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Listen to the Task deleting event. |
||
| 37 | * |
||
| 38 | * @param \App\Task $task |
||
| 39 | * |
||
| 40 | * @return void |
||
| 41 | */ |
||
| 42 | public function deleted(Task $task) |
||
| 43 | { |
||
| 44 | if (Auth::check()) { |
||
| 45 | $username = Auth::user()->name; |
||
| 46 | } else { |
||
| 47 | $username = User::findOrFail($task->user_id)->name; |
||
| 48 | } |
||
| 49 | TaskEvent::create([ |
||
| 50 | 'time' => Carbon::now(), |
||
| 51 | 'task_name' => $task->name, |
||
| 52 | 'user_name' => $username, |
||
| 53 | 'type' => 'deleted', |
||
| 54 | ]); |
||
| 55 | } |
||
| 56 | |||
| 57 | public function retrieved(Task $task) |
||
| 58 | { |
||
| 59 | } |
||
| 60 | |||
| 61 | public function updated(Task $task) |
||
| 73 | ]); |
||
| 74 | } |
||
| 75 | |||
| 76 | public function saved(Task $task) |
||
| 78 | } |
||
| 79 | } |
||
| 80 |