@@ -33,7 +33,7 @@ |
||
| 33 | 33 | /** |
| 34 | 34 | * Get the user that the activity belongs to. |
| 35 | 35 | * |
| 36 | - * @return object |
|
| 36 | + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
|
| 37 | 37 | */ |
| 38 | 38 | public function user() |
| 39 | 39 | { |
@@ -18,16 +18,16 @@ discard block |
||
| 18 | 18 | * @var array |
| 19 | 19 | */ |
| 20 | 20 | protected $fillable = [ |
| 21 | - 'user_id', |
|
| 22 | - 'content_type', |
|
| 23 | - 'content_id', |
|
| 24 | - 'action', |
|
| 25 | - 'description', |
|
| 26 | - 'details', |
|
| 27 | - 'data', |
|
| 28 | - 'version', |
|
| 29 | - 'ip_address', |
|
| 30 | - 'user_agent', |
|
| 21 | + 'user_id', |
|
| 22 | + 'content_type', |
|
| 23 | + 'content_id', |
|
| 24 | + 'action', |
|
| 25 | + 'description', |
|
| 26 | + 'details', |
|
| 27 | + 'data', |
|
| 28 | + 'version', |
|
| 29 | + 'ip_address', |
|
| 30 | + 'user_agent', |
|
| 31 | 31 | ]; |
| 32 | 32 | |
| 33 | 33 | /** |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | */ |
| 38 | 38 | public function user() |
| 39 | 39 | { |
| 40 | - return $this->belongsTo(config('auth.providers.users.model'), 'user_id'); |
|
| 40 | + return $this->belongsTo(config('auth.providers.users.model'), 'user_id'); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /** |
@@ -48,49 +48,49 @@ discard block |
||
| 48 | 48 | */ |
| 49 | 49 | public static function log($data = []) |
| 50 | 50 | { |
| 51 | - // set the defaults from config |
|
| 52 | - $defaults = config('activity-log.defaults'); |
|
| 53 | - if (!is_array($defaults)) { |
|
| 54 | - $defaults = []; |
|
| 55 | - } |
|
| 51 | + // set the defaults from config |
|
| 52 | + $defaults = config('activity-log.defaults'); |
|
| 53 | + if (!is_array($defaults)) { |
|
| 54 | + $defaults = []; |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - if (is_object($data)) { |
|
| 58 | - $data = (array) $data; |
|
| 59 | - } |
|
| 57 | + if (is_object($data)) { |
|
| 58 | + $data = (array) $data; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - // set the user ID |
|
| 62 | - if (config('activity-log.auto_set_user_id') && !isset($data['userId'])) { |
|
| 63 | - $user = call_user_func(config('activity-log.auth_method')); |
|
| 64 | - $data['userId'] = isset($user->id) ? $user->id : null; |
|
| 65 | - } |
|
| 61 | + // set the user ID |
|
| 62 | + if (config('activity-log.auto_set_user_id') && !isset($data['userId'])) { |
|
| 63 | + $user = call_user_func(config('activity-log.auth_method')); |
|
| 64 | + $data['userId'] = isset($user->id) ? $user->id : null; |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - // set IP address |
|
| 68 | - if (!isset($data['ipAddress'])) { |
|
| 69 | - $data['ipAddress'] = Request::getClientIp(); |
|
| 70 | - } |
|
| 67 | + // set IP address |
|
| 68 | + if (!isset($data['ipAddress'])) { |
|
| 69 | + $data['ipAddress'] = Request::getClientIp(); |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - // set user agent |
|
| 73 | - if (!isset($data['userAgent'])) { |
|
| 74 | - $data['userAgent'] = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'No User Agent'; |
|
| 75 | - } |
|
| 72 | + // set user agent |
|
| 73 | + if (!isset($data['userAgent'])) { |
|
| 74 | + $data['userAgent'] = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'No User Agent'; |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - // set additional data and encode it as JSON if it is an array or an object |
|
| 78 | - if (isset($data['data']) && (is_array($data['data']) || is_object($data['data']))) { |
|
| 79 | - $data['data'] = json_encode($data['data']); |
|
| 80 | - } |
|
| 77 | + // set additional data and encode it as JSON if it is an array or an object |
|
| 78 | + if (isset($data['data']) && (is_array($data['data']) || is_object($data['data']))) { |
|
| 79 | + $data['data'] = json_encode($data['data']); |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - // format array keys to snake case for insertion into database |
|
| 83 | - $dataFormatted = []; |
|
| 84 | - foreach ($data as $key => $value) { |
|
| 85 | - $dataFormatted[snake_case($key)] = $value; |
|
| 86 | - } |
|
| 82 | + // format array keys to snake case for insertion into database |
|
| 83 | + $dataFormatted = []; |
|
| 84 | + foreach ($data as $key => $value) { |
|
| 85 | + $dataFormatted[snake_case($key)] = $value; |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - // merge defaults array with formatted data array |
|
| 89 | - $data = array_merge($defaults, $dataFormatted); |
|
| 88 | + // merge defaults array with formatted data array |
|
| 89 | + $data = array_merge($defaults, $dataFormatted); |
|
| 90 | 90 | |
| 91 | - // create the record |
|
| 92 | - $self = static::create($data); |
|
| 91 | + // create the record |
|
| 92 | + $self = static::create($data); |
|
| 93 | 93 | |
| 94 | - return $self; |
|
| 94 | + return $self; |
|
| 95 | 95 | } |
| 96 | 96 | } |
@@ -17,15 +17,15 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | public function boot() |
| 19 | 19 | {
|
| 20 | - $this->publishes([ |
|
| 21 | - __DIR__ . '/config/activity-log.php' => config_path('activity-log.php'),
|
|
| 22 | - ]); |
|
| 20 | + $this->publishes([ |
|
| 21 | + __DIR__ . '/config/activity-log.php' => config_path('activity-log.php'),
|
|
| 22 | + ]); |
|
| 23 | 23 | |
| 24 | - $this->publishes([ |
|
| 25 | - __DIR__ . '/migrations' => database_path('migrations'),
|
|
| 26 | - ], 'migrations'); |
|
| 24 | + $this->publishes([ |
|
| 25 | + __DIR__ . '/migrations' => database_path('migrations'),
|
|
| 26 | + ], 'migrations'); |
|
| 27 | 27 | |
| 28 | - $this->mergeConfigFrom(__DIR__ . '/config/activity-log.php', 'activity-log'); |
|
| 28 | + $this->mergeConfigFrom(__DIR__ . '/config/activity-log.php', 'activity-log'); |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | /** |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | public function register() |
| 37 | 37 | {
|
| 38 | - // |
|
| 38 | + // |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | /** |
@@ -45,6 +45,6 @@ discard block |
||
| 45 | 45 | */ |
| 46 | 46 | public function provides() |
| 47 | 47 | {
|
| 48 | - return []; |
|
| 48 | + return []; |
|
| 49 | 49 | } |
| 50 | 50 | } |