@@ -3,48 +3,48 @@ |
||
| 3 | 3 | use Illuminate\Support\ServiceProvider; |
| 4 | 4 | |
| 5 | 5 | class ActivityLogServiceProvider extends ServiceProvider {
|
| 6 | - /** |
|
| 7 | - * Indicates if loading of the provider is deferred. |
|
| 8 | - * |
|
| 9 | - * @var bool |
|
| 10 | - */ |
|
| 11 | - protected $defer = false; |
|
| 6 | + /** |
|
| 7 | + * Indicates if loading of the provider is deferred. |
|
| 8 | + * |
|
| 9 | + * @var bool |
|
| 10 | + */ |
|
| 11 | + protected $defer = false; |
|
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * Bootstrap the application events. |
|
| 15 | - * |
|
| 16 | - * @return void |
|
| 17 | - */ |
|
| 18 | - public function boot() |
|
| 19 | - {
|
|
| 13 | + /** |
|
| 14 | + * Bootstrap the application events. |
|
| 15 | + * |
|
| 16 | + * @return void |
|
| 17 | + */ |
|
| 18 | + public function boot() |
|
| 19 | + {
|
|
| 20 | 20 | $this->publishes([ |
| 21 | - __DIR__ . '/config/activity-log.php' => config_path('activity-log.php'),
|
|
| 21 | + __DIR__ . '/config/activity-log.php' => config_path('activity-log.php'),
|
|
| 22 | 22 | ]); |
| 23 | 23 | |
| 24 | 24 | $this->publishes([ |
| 25 | - __DIR__ . '/migrations' => database_path('migrations'),
|
|
| 25 | + __DIR__ . '/migrations' => database_path('migrations'),
|
|
| 26 | 26 | ], 'migrations'); |
| 27 | 27 | |
| 28 | 28 | $this->mergeConfigFrom(__DIR__ . '/config/activity-log.php', 'activity-log'); |
| 29 | - } |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Register the service provider. |
|
| 33 | - * |
|
| 34 | - * @return void |
|
| 35 | - */ |
|
| 36 | - public function register() |
|
| 37 | - {
|
|
| 31 | + /** |
|
| 32 | + * Register the service provider. |
|
| 33 | + * |
|
| 34 | + * @return void |
|
| 35 | + */ |
|
| 36 | + public function register() |
|
| 37 | + {
|
|
| 38 | 38 | // |
| 39 | - } |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * Get the services provided by the provider. |
|
| 43 | - * |
|
| 44 | - * @return array |
|
| 45 | - */ |
|
| 46 | - public function provides() |
|
| 47 | - {
|
|
| 41 | + /** |
|
| 42 | + * Get the services provided by the provider. |
|
| 43 | + * |
|
| 44 | + * @return array |
|
| 45 | + */ |
|
| 46 | + public function provides() |
|
| 47 | + {
|
|
| 48 | 48 | return []; |
| 49 | - } |
|
| 49 | + } |
|
| 50 | 50 | } |
@@ -1,29 +1,29 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | return [ |
| 4 | - /** |
|
| 5 | - * Auto Set User ID |
|
| 6 | - * |
|
| 7 | - * If false, user ID will not be automatically set. |
|
| 8 | - */ |
|
| 9 | - 'auto_set_user_id' => true, |
|
| 4 | + /** |
|
| 5 | + * Auto Set User ID |
|
| 6 | + * |
|
| 7 | + * If false, user ID will not be automatically set. |
|
| 8 | + */ |
|
| 9 | + 'auto_set_user_id' => true, |
|
| 10 | 10 | |
| 11 | - /** |
|
| 12 | - * Auth driver |
|
| 13 | - * |
|
| 14 | - * If you are using any alternative packages for Authentication |
|
| 15 | - * and User management then you can put in the appropriate |
|
| 16 | - * function to get the currently logged in user. |
|
| 17 | - * For example, if you are using Sentry, |
|
| 18 | - * you would put Sentry::getUser() |
|
| 19 | - * instead of Laravel's default which is Auth::user(). |
|
| 20 | - */ |
|
| 21 | - 'auth_method' => '\Auth::user', |
|
| 11 | + /** |
|
| 12 | + * Auth driver |
|
| 13 | + * |
|
| 14 | + * If you are using any alternative packages for Authentication |
|
| 15 | + * and User management then you can put in the appropriate |
|
| 16 | + * function to get the currently logged in user. |
|
| 17 | + * For example, if you are using Sentry, |
|
| 18 | + * you would put Sentry::getUser() |
|
| 19 | + * instead of Laravel's default which is Auth::user(). |
|
| 20 | + */ |
|
| 21 | + 'auth_method' => '\Auth::user', |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Default Values |
|
| 25 | - */ |
|
| 26 | - 'defaults' => [ |
|
| 27 | - ], |
|
| 23 | + /** |
|
| 24 | + * Default Values |
|
| 25 | + */ |
|
| 26 | + 'defaults' => [ |
|
| 27 | + ], |
|
| 28 | 28 | |
| 29 | 29 | ]; |
@@ -5,19 +5,19 @@ discard block |
||
| 5 | 5 | use Illuminate\Support\Facades\Request; |
| 6 | 6 | |
| 7 | 7 | class Activity extends Eloquent { |
| 8 | - /** |
|
| 9 | - * The database table used by the model. |
|
| 10 | - * |
|
| 11 | - * @var string |
|
| 12 | - */ |
|
| 13 | - protected $table = 'activity_log'; |
|
| 14 | - |
|
| 15 | - /** |
|
| 16 | - * The fillable fields for the model. |
|
| 17 | - * |
|
| 18 | - * @var array |
|
| 19 | - */ |
|
| 20 | - protected $fillable = [ |
|
| 8 | + /** |
|
| 9 | + * The database table used by the model. |
|
| 10 | + * |
|
| 11 | + * @var string |
|
| 12 | + */ |
|
| 13 | + protected $table = 'activity_log'; |
|
| 14 | + |
|
| 15 | + /** |
|
| 16 | + * The fillable fields for the model. |
|
| 17 | + * |
|
| 18 | + * @var array |
|
| 19 | + */ |
|
| 20 | + protected $fillable = [ |
|
| 21 | 21 | 'user_id', |
| 22 | 22 | 'content', |
| 23 | 23 | 'content_id', |
@@ -28,71 +28,71 @@ discard block |
||
| 28 | 28 | 'version', |
| 29 | 29 | 'ip_address', |
| 30 | 30 | 'user_agent', |
| 31 | - ]; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * Get the user that the activity belongs to. |
|
| 35 | - * |
|
| 36 | - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
|
| 37 | - */ |
|
| 38 | - public function user() |
|
| 39 | - { |
|
| 31 | + ]; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * Get the user that the activity belongs to. |
|
| 35 | + * |
|
| 36 | + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
|
| 37 | + */ |
|
| 38 | + public function user() |
|
| 39 | + { |
|
| 40 | 40 | return $this->belongsTo(config('auth.providers.users.model'), 'user_id'); |
| 41 | - } |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Create an activity log entry. |
|
| 45 | - * |
|
| 46 | - * @param mixed $data |
|
| 47 | - * @return boolean |
|
| 48 | - */ |
|
| 49 | - public static function log($data = []) |
|
| 50 | - { |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Create an activity log entry. |
|
| 45 | + * |
|
| 46 | + * @param mixed $data |
|
| 47 | + * @return boolean |
|
| 48 | + */ |
|
| 49 | + public static function log($data = []) |
|
| 50 | + { |
|
| 51 | 51 | // set the defaults from config |
| 52 | 52 | $defaults = config('activity-log.defaults'); |
| 53 | 53 | if (!is_array($defaults)) { |
| 54 | - $defaults = []; |
|
| 54 | + $defaults = []; |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | if (is_object($data)) { |
| 58 | - $data = (array) $data; |
|
| 58 | + $data = (array) $data; |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | // conversion path to content |
| 62 | 62 | if (isset($data['contentType']) && !isset($data['content'])) { |
| 63 | - $data['content'] = $data['contentType']; |
|
| 63 | + $data['content'] = $data['contentType']; |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | // conversion path to state |
| 67 | 67 | if (isset($data['description']) && !isset($data['state'])) { |
| 68 | - $data['state'] = $data['description']; |
|
| 68 | + $data['state'] = $data['description']; |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | // set the user ID |
| 72 | 72 | if (config('activity-log.auto_set_user_id') && !isset($data['userId'])) { |
| 73 | - $user = call_user_func(config('activity-log.auth_method')); |
|
| 74 | - $data['userId'] = isset($user->id) ? $user->id : null; |
|
| 73 | + $user = call_user_func(config('activity-log.auth_method')); |
|
| 74 | + $data['userId'] = isset($user->id) ? $user->id : null; |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | // set IP address |
| 78 | 78 | if (!isset($data['ipAddress'])) { |
| 79 | - $data['ipAddress'] = Request::getClientIp(); |
|
| 79 | + $data['ipAddress'] = Request::getClientIp(); |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | // set user agent |
| 83 | 83 | if (!isset($data['userAgent'])) { |
| 84 | - $data['userAgent'] = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'No User Agent'; |
|
| 84 | + $data['userAgent'] = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'No User Agent'; |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | // set additional data and encode it as JSON if it is an array or an object |
| 88 | 88 | if (isset($data['data']) && (is_array($data['data']) || is_object($data['data']))) { |
| 89 | - $data['data'] = json_encode($data['data']); |
|
| 89 | + $data['data'] = json_encode($data['data']); |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | // format array keys to snake case for insertion into database |
| 93 | 93 | $dataFormatted = []; |
| 94 | 94 | foreach ($data as $key => $value) { |
| 95 | - $dataFormatted[snake_case($key)] = $value; |
|
| 95 | + $dataFormatted[snake_case($key)] = $value; |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | // merge defaults array with formatted data array |
@@ -102,5 +102,5 @@ discard block |
||
| 102 | 102 | $self = static::create($data); |
| 103 | 103 | |
| 104 | 104 | return $self; |
| 105 | - } |
|
| 105 | + } |
|
| 106 | 106 | } |