| @@ 7-67 (lines=61) @@ | ||
| 4 | use Illuminate\Support\Facades\Auth; |
|
| 5 | use Xetaravel\Models\Presenters\DiscussLogPresenter; |
|
| 6 | ||
| 7 | class DiscussLog extends Model |
|
| 8 | { |
|
| 9 | use DiscussLogPresenter; |
|
| 10 | ||
| 11 | /** |
|
| 12 | * The attributes that are mass assignable. |
|
| 13 | * |
|
| 14 | * @var array |
|
| 15 | */ |
|
| 16 | protected $fillable = [ |
|
| 17 | 'user_id', |
|
| 18 | 'loggable_id', |
|
| 19 | 'loggable_type', |
|
| 20 | 'event_type', |
|
| 21 | 'data' |
|
| 22 | ]; |
|
| 23 | ||
| 24 | /** |
|
| 25 | * The attributes that should be cast to native types. |
|
| 26 | * |
|
| 27 | * @var array |
|
| 28 | */ |
|
| 29 | protected $casts = [ |
|
| 30 | 'data' => 'array' |
|
| 31 | ]; |
|
| 32 | ||
| 33 | /** |
|
| 34 | * The "booting" method of the model. |
|
| 35 | * |
|
| 36 | * @return void |
|
| 37 | */ |
|
| 38 | protected static function boot() |
|
| 39 | { |
|
| 40 | parent::boot(); |
|
| 41 | ||
| 42 | // Set the user id to the new log before saving it. |
|
| 43 | static::creating(function ($model) { |
|
| 44 | $model->user_id = Auth::id(); |
|
| 45 | }); |
|
| 46 | } |
|
| 47 | ||
| 48 | /** |
|
| 49 | * Get the user that owns the log. |
|
| 50 | * |
|
| 51 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
|
| 52 | */ |
|
| 53 | public function user() |
|
| 54 | { |
|
| 55 | return $this->belongsTo(User::class); |
|
| 56 | } |
|
| 57 | ||
| 58 | /** |
|
| 59 | * Get the loggable relation. |
|
| 60 | * |
|
| 61 | * @return \Illuminate\Database\Eloquent\Relations\MorphTo |
|
| 62 | */ |
|
| 63 | public function loggable() |
|
| 64 | { |
|
| 65 | return $this->morphTo(); |
|
| 66 | } |
|
| 67 | } |
|
| 68 | ||
| @@ 7-67 (lines=61) @@ | ||
| 4 | use Illuminate\Support\Facades\Auth; |
|
| 5 | use Xetaravel\Models\Presenters\UserExperiencePresenter; |
|
| 6 | ||
| 7 | class UserExperience extends Model |
|
| 8 | { |
|
| 9 | use UserExperiencePresenter; |
|
| 10 | ||
| 11 | /** |
|
| 12 | * The attributes that are mass assignable. |
|
| 13 | * |
|
| 14 | * @var array |
|
| 15 | */ |
|
| 16 | protected $fillable = [ |
|
| 17 | 'user_id', |
|
| 18 | 'obtainable_id', |
|
| 19 | 'obtainable_type', |
|
| 20 | 'event_type', |
|
| 21 | 'data' |
|
| 22 | ]; |
|
| 23 | ||
| 24 | /** |
|
| 25 | * The attributes that should be cast to native types. |
|
| 26 | * |
|
| 27 | * @var array |
|
| 28 | */ |
|
| 29 | protected $casts = [ |
|
| 30 | 'data' => 'array' |
|
| 31 | ]; |
|
| 32 | ||
| 33 | /** |
|
| 34 | * The "booting" method of the model. |
|
| 35 | * |
|
| 36 | * @return void |
|
| 37 | */ |
|
| 38 | protected static function boot() |
|
| 39 | { |
|
| 40 | parent::boot(); |
|
| 41 | ||
| 42 | // Set the user id to the new log before saving it. |
|
| 43 | static::creating(function ($model) { |
|
| 44 | $model->user_id = Auth::id(); |
|
| 45 | }); |
|
| 46 | } |
|
| 47 | ||
| 48 | /** |
|
| 49 | * Get the user that owns the log. |
|
| 50 | * |
|
| 51 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
|
| 52 | */ |
|
| 53 | public function user() |
|
| 54 | { |
|
| 55 | return $this->belongsTo(User::class); |
|
| 56 | } |
|
| 57 | ||
| 58 | /** |
|
| 59 | * Get the obtainable relation. |
|
| 60 | * |
|
| 61 | * @return \Illuminate\Database\Eloquent\Relations\MorphTo |
|
| 62 | */ |
|
| 63 | public function obtainable() |
|
| 64 | { |
|
| 65 | return $this->morphTo(); |
|
| 66 | } |
|
| 67 | } |
|
| 68 | ||