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/ehbo.today/app/KommaApp/Documents/Models/Document.php
<?php

namespace App\KommaApp\Documents\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\UploadedFile;

/**
 * Class Document
 * 
 * Represents a document in the database
 * 
 * Transient properties (Not saved to the database)
 *
 * @property UploadedFile file
 * @property string $state;
 * @package App\KommaApp\Files\Model
 * @property-read \Illuminate\Database\Eloquent\Model|\Eloquent $documentable
 * @mixin \Eloquent
 * @property int $id
 * @property string $name
 * @property string $path
 * @property int $sort_order
 * @property int $documentable_id
 * @property string $documentable_type
 * @property string $thumb_image_url
 * @property string $small_image_url
 * @property string $medium_image_url
 * @property string $large_image_url
 * @property \Carbon\Carbon|null $created_at
 * @property \Carbon\Carbon|null $updated_at
 * @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Documents\Models\Document whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Documents\Models\Document whereDocumentableId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Documents\Models\Document whereDocumentableType($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Documents\Models\Document whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Documents\Models\Document whereLargeImageUrl($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Documents\Models\Document whereMediumImageUrl($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Documents\Models\Document whereName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Documents\Models\Document wherePath($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Documents\Models\Document whereSmallImageUrl($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Documents\Models\Document whereSortOrder($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Documents\Models\Document whereThumbImageUrl($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Documents\Models\Document whereUpdatedAt($value)
 * @property string $mime_type
 * @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Documents\Models\Document whereMimeType($value)
 * @property string $key
 * @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Documents\Models\Document whereKey($value)
 * @property string $original_image_url
 * @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Documents\Models\Document whereOriginalImageUrl($value)
 */
class Document extends Model
{
    const STATE_NEW = 'new';
    const STATE_PRISTINE = 'pristine';
    const STATE_MODIFIED = 'modified';
    const STATE_DELETED = 'deleted';

    protected $fillable = ['path', 'name', 'sort_order', 'documentable_id', 'documentable_type', 'thumb_image_url', 'small_image_url', 'medium_image_url', 'large_image_url'];

    /** @var UploadedFile $file associated with the document */
    public $file;

    /** @var string $state The state of the document */
    public $state = self::STATE_PRISTINE;

    public function documentable()
    {
        return $this->morphTo();
    }

    /**
     * Convert the object into something JSON serializable.
     *
     * @return array
     */
    public function toArray()
    {
        $array = parent::toArray();
        $array['state'] = $this->state;
        return $array;
    }

    /**
     * Checks if the document is a certain mime type
     *
     * @param string $method
     * @param array $parameters
     * @return mixed
     */
    public function __call($method, $parameters)
    {
        //Check if we are going to check if the document is of a certain mime type type. If this document is of mime type "image/png". The type is "image" and we can magically check it with a call to the magic isImage method.
        if($this->mime_type != '' && substr($method, 0, 2) == 'is')
        {
            $possibleMimeType = strtolower(substr($method, 2)); //The type part of the mime type. Not the tree part.
            $mimeParts = explode('/', $this->mime_type);
            $explodedMimeTypeType = array_shift($mimeParts);
            return $explodedMimeTypeType == $possibleMimeType;
        }

        return parent::__call($method, $parameters); //Pass the call further into laravel and return its result
    }
}