@@ -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 | { |
@@ -1,7 +1,6 @@ |
||
1 | 1 | <?php namespace JackJoe\ActivityLog\Models; |
2 | 2 | |
3 | 3 | use Illuminate\Database\Eloquent\Model as Eloquent; |
4 | -use Illuminate\Support\Facades\Auth; |
|
5 | 4 | use Illuminate\Support\Facades\Request; |
6 | 5 | |
7 | 6 | class Activity extends Eloquent { |
@@ -50,34 +50,34 @@ |
||
50 | 50 | { |
51 | 51 | // set the defaults from config |
52 | 52 | $defaults = config('activity-log.defaults'); |
53 | - if(!is_array($defaults)) { |
|
53 | + if(!is_array($defaults)) { |
|
54 | 54 | $defaults = []; |
55 | - } |
|
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 |
|
61 | + // set the user ID |
|
62 | 62 | if(config('activity-log.auto_set_user_id') && !isset($data['userId'])) { |
63 | - $user = call_user_func(config('activity-log.auth_method')); |
|
63 | + $user = call_user_func(config('activity-log.auth_method')); |
|
64 | 64 | $data['userId'] = isset($user->id) ? $user->id : null; |
65 | 65 | } |
66 | 66 | |
67 | 67 | // set IP address |
68 | - if(!isset($data['ipAddress'])) { |
|
68 | + if(!isset($data['ipAddress'])) { |
|
69 | 69 | $data['ipAddress'] = Request::getClientIp(); |
70 | - } |
|
70 | + } |
|
71 | 71 | |
72 | 72 | // set user agent |
73 | - if (!isset($data['userAgent'])) { |
|
73 | + if (!isset($data['userAgent'])) { |
|
74 | 74 | $data['userAgent'] = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'No User Agent'; |
75 | - } |
|
75 | + } |
|
76 | 76 | |
77 | 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']))) { |
|
78 | + if(isset($data['data']) && (is_array($data['data']) || is_object($data['data']))) { |
|
79 | 79 | $data['data'] = json_encode($data['data']); |
80 | - } |
|
80 | + } |
|
81 | 81 | |
82 | 82 | // format array keys to snake case for insertion into database |
83 | 83 | $dataFormatted = []; |
@@ -50,22 +50,22 @@ discard block |
||
50 | 50 | { |
51 | 51 | // set the defaults from config |
52 | 52 | $defaults = config('activity-log.defaults'); |
53 | - if(!is_array($defaults)) { |
|
53 | + if (!is_array($defaults)) { |
|
54 | 54 | $defaults = []; |
55 | 55 | } |
56 | 56 | |
57 | - if(is_object($data)) { |
|
57 | + if (is_object($data)) { |
|
58 | 58 | $data = (array) $data; |
59 | 59 | } |
60 | 60 | |
61 | 61 | // set the user ID |
62 | - if(config('activity-log.auto_set_user_id') && !isset($data['userId'])) { |
|
62 | + if (config('activity-log.auto_set_user_id') && !isset($data['userId'])) { |
|
63 | 63 | $user = call_user_func(config('activity-log.auth_method')); |
64 | 64 | $data['userId'] = isset($user->id) ? $user->id : null; |
65 | 65 | } |
66 | 66 | |
67 | 67 | // set IP address |
68 | - if(!isset($data['ipAddress'])) { |
|
68 | + if (!isset($data['ipAddress'])) { |
|
69 | 69 | $data['ipAddress'] = Request::getClientIp(); |
70 | 70 | } |
71 | 71 | |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | } |
76 | 76 | |
77 | 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']))) { |
|
78 | + if (isset($data['data']) && (is_array($data['data']) || is_object($data['data']))) { |
|
79 | 79 | $data['data'] = json_encode($data['data']); |
80 | 80 | } |
81 | 81 |
@@ -11,27 +11,27 @@ discard block |
||
11 | 11 | */ |
12 | 12 | public function up() |
13 | 13 | { |
14 | - Schema::create('activity_log', function(Blueprint $table) |
|
15 | - { |
|
16 | - $table->increments('id'); |
|
14 | + Schema::create('activity_log', function(Blueprint $table) |
|
15 | + { |
|
16 | + $table->increments('id'); |
|
17 | 17 | |
18 | - $table->integer('user_id')->nullable(); |
|
19 | - $table->integer('content_id')->nullable(); |
|
18 | + $table->integer('user_id')->nullable(); |
|
19 | + $table->integer('content_id')->nullable(); |
|
20 | 20 | |
21 | - $table->string('content_type', 72)->nullable(); |
|
22 | - $table->string('action', 32)->nullable(); |
|
23 | - $table->string('description')->nullable(); |
|
21 | + $table->string('content_type', 72)->nullable(); |
|
22 | + $table->string('action', 32)->nullable(); |
|
23 | + $table->string('description')->nullable(); |
|
24 | 24 | |
25 | - $table->longText('details')->nullable(); |
|
26 | - $table->longText('data')->nullable(); |
|
25 | + $table->longText('details')->nullable(); |
|
26 | + $table->longText('data')->nullable(); |
|
27 | 27 | |
28 | - $table->string('version', 10)->nullable(); |
|
29 | - $table->string('ip_address', 64); |
|
30 | - $table->string('user_agent'); |
|
28 | + $table->string('version', 10)->nullable(); |
|
29 | + $table->string('ip_address', 64); |
|
30 | + $table->string('user_agent'); |
|
31 | 31 | |
32 | - $table->timestamp('created_at')->useCurrent(); |
|
33 | - $table->timestamp('updated_at')->useCurrent(); |
|
34 | - }); |
|
32 | + $table->timestamp('created_at')->useCurrent(); |
|
33 | + $table->timestamp('updated_at')->useCurrent(); |
|
34 | + }); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | /** |
@@ -41,6 +41,6 @@ discard block |
||
41 | 41 | */ |
42 | 42 | public function down() |
43 | 43 | { |
44 | - Schema::drop('activity_log'); |
|
44 | + Schema::drop('activity_log'); |
|
45 | 45 | } |
46 | 46 | } |
@@ -23,9 +23,9 @@ |
||
23 | 23 | |
24 | 24 | $this->publishes([ |
25 | 25 | __DIR__ . '/migrations' => database_path('migrations'), |
26 | - ], '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 | /** |