Completed
Push — master ( fac72b...14ba86 )
by Faiq
14s
created

Common::currentUser()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App;
4
5
use Illuminate\Support\Facades\Auth;
6
7
class Common
8
{
9
10
    /**
11
     * Register new activity log
12
     *
13
     * @param $data
14
     * @return bool
15
     */
16
    public static function registerLog($data) {
17
        $log = new Log;
18
19
        $log->action = $data['action'];
20
        $log->target = $data['target'];
21
        $log->prefix = $data['prefix'];
22
23
        switch($data['target']) {
24
            case 'thread'   : $log->thread_id = $data['target_id']; break;
25
            case 'article'  : $log->article_id = $data['target_id']; break;
26
        }
27
28
        switch ($data['actor']) {
29
            case 'admin'    : $log->admin_id = $data['actor_id'];   break;
30
            case 'doctor'   : $log->doctor_id = $data['actor_id'];  break;
31
            case 'user'     : $log->user_id = $data['actor_id'];  break;
32
        }
33
34
        if($log->save()) {
35
            return true;
36
        }
37
38
        return false;
39
    }
40
41
    /**
42
     * Get current logged in user
43
     *
44
     * @return mixed
45
     */
46
    public static function currentUser($guard)
47
    {
48
        return Auth::guard($guard)->user();
49
    }
50
51
}
52