1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of the Laravel Platfourm package. |
4
|
|
|
* |
5
|
|
|
* (c) Avtandil Kikabidze aka LONGMAN <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Longman\Platfourm\Database\Eloquent\ActionLog; |
12
|
|
|
|
13
|
|
|
use Longman\Platfourm\Database\Eloquent\Model; |
14
|
|
|
use Longman\Platfourm\User\Models\Eloquent\User; |
15
|
|
|
|
16
|
|
|
class ActionLog extends Model |
17
|
|
|
{ |
18
|
|
|
|
19
|
|
|
public $timestamps = false; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* The database table used by the model. |
23
|
|
|
* |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
protected $table = 'action_log'; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* The attributes that are mass assignable. |
30
|
|
|
* |
31
|
|
|
* @var array |
32
|
|
|
*/ |
33
|
|
|
protected $fillable = [ |
34
|
|
|
'user_id', 'lang', 'entity', 'scope', 'action', 'url', 'referer', 'before_data', |
35
|
|
|
'after_data', 'request_data', 'ip_address', 'user_agent' |
36
|
|
|
]; |
37
|
|
|
|
38
|
|
|
protected $casts = [ |
39
|
|
|
'before_data' => 'array', |
40
|
|
|
'after_data' => 'array', |
41
|
|
|
'request_data' => 'array', |
42
|
|
|
]; |
43
|
|
|
|
44
|
|
|
|
45
|
|
|
public static function boot() |
46
|
|
|
{ |
47
|
|
|
static::creating(function ($model) { |
48
|
|
|
$model->created_at = $model->freshTimestamp(); |
49
|
|
|
}); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
View Code Duplication |
public function user() |
|
|
|
|
53
|
|
|
{ |
54
|
|
|
$model = User::class; |
55
|
|
|
if (class_exists(\App\Models\User::class)) { |
56
|
|
|
$model = \App\Models\User::class; |
57
|
|
|
} |
58
|
|
|
return $this->hasOne($model); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
} |
62
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.