isSuperUser()) { $actionlog->company_id = $actionlog->target->company_id; } else if (Auth::user() && Auth::user()->company) { $actionlog->company_id = Auth::user()->company_id; } }); } // Eloquent Relationships below public function item() { return $this->morphTo('item')->withTrashed(); } public function itemType() { if($this->item_type == AssetModel::class) { return "model"; } return camel_case(class_basename($this->item_type)); } public function uploads() { return $this->morphTo('item') ->where('action_type', '=', 'uploaded') ->withTrashed(); } public function userlog() { return $this->target(); } public function user() { return $this->belongsTo(User::class, 'user_id') ->withTrashed(); } public function target() { return $this->morphTo('target'); } public function childlogs() { return $this->hasMany('\App\Models\ActionLog', 'thread_id'); } public function parentlog() { return $this->belongsTo('\App\Models\ActionLog', 'thread_id'); } /** * Check if the file exists, and if it does, force a download **/ public function get_src($type = 'assets') { $file = config('app.private_uploads') . '/' . $type . '/' . $this->filename; return $file; } /** * Get the parent category name */ public function logaction($actiontype) { $this->action_type = $actiontype; if ($this->save()) { return true; } else { return false; } } /** * getListingOfActionLogsChronologicalOrder * * @return mixed * @author Vincent Sposato * @version v1.0 */ public function getListingOfActionLogsChronologicalOrder() { return $this->all() ->where('action_type', '!=', 'uploaded') ->orderBy('item_id', 'asc') ->orderBy('created_at', 'asc') ->get(); } }