HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/gggg.komma.nl/vendor/komma/kms/src/ActionLog/Models/ActionLog.php
<?php


namespace Komma\KMS\ActionLog\Models;

use Komma\KMS\Users\Models\KmsUser;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphTo;

/**
 * Class ActionLog
 * 
 * An action that was performed and logged
 *
 * @package App\Kms\ActionLog
 * @property-read \Komma\KMS\Users\Models\KmsUser $User
 * @property string $action
 * @property mixed $payload
 * @mixin \Eloquent
 * @property int $id
 * @property int|null $user_id
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @method static \Illuminate\Database\Eloquent\Builder|ActionLog whereAction($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ActionLog whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ActionLog whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ActionLog wherePayload($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ActionLog whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ActionLog whereUserId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ActionLog newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|ActionLog newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|ActionLog query()
 */
final class ActionLog extends Model
{
    /**
     * @see SiteUser
     * @see KmsUser
     * @see HasActionLogs
     * @return MorphTo
     * @throws \Exception
     */
    public function authenticatable():MorphTo
    {
        return $this->morphTo();
    }

    /**
     * Help full check to check if there is an authenticatable. If you would use the
     * authenticatable method directly while authenticatable_id and type are null, you would get this exception:
     * PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'action_logs.' in 'where clause'.
     */
    public function hasAuthenticatable(): bool
    {
        return ($this->authenticatable_id && $this->authenticatable_type);
    }

    public function setPayloadAttribute($value)
    {
        if($value) $this->attributes['payload'] = serialize($value);
    }

    public function getPayloadAttribute()
    {
        return ($this->attributes['payload']) ? unserialize($this->attributes['payload']) : null;
    }

    public function __toString()
    {
        $date = $this->attributes[$this->getCreatedAtColumn()];

        $log = '['.$date.'] ';
        $log .= ($this->authenticatable) ? $this->authenticatable->username.': ' : __('KMS::actionlog.anonymous').': ';
        $log .= $this->action;

        return $log;
    }
}