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/meulendijk.komma.pro/app/KommaApp/Users/Models/Role.php
<?php

namespace App\KommaApp\Users\Models;

use Illuminate\Database\Eloquent\Model;

/**
 * App\KommaApp\Users\Models\Role
 *
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\KommaApp\Users\Models\User[] $users
 * @mixin \Eloquent
 * @property int $id
 * @property string $name
 * @property int $value
 * @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Users\Models\Role whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Users\Models\Role whereName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Users\Models\Role whereValue($value)
 */
class Role extends Model {

    const SuperAdmin = 1;
    const Admin = 2;
    const Editor = 3;
    const Customer = 4;

    protected $kmsClass = Role::class;

    /*
    * Transient properties on Eloquent models
    * These are not saved to database.
    */
    public $thumbnail = false;


    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table = 'roles';


    protected $fillable = ['name', 'value'];

    public function users()
    {
        return $this->hasMany(User::class);
    }

    /**
     * Checks if the specified compare value is
     *
     * @param null|int|role $compare
     * @return bool
     */
    public function isAtLeast($compare = null)
    {
        if($compare == null) return true;
        elseif(is_numeric($compare))
            return $this->value <= $compare;
        elseif(is_a($compare, Role::class))
            return $this->value <= $compare->value;
    }

    /**
     * @return int[] All roles as an array of integers
     */
    static function getAsArray() {
        return self::getAllRoles();
    }

    /**
     * Returns an array containing integers representing the defined roles.
     *
     * @return int[]
     */
    private static function getAllRoles()
    {
        $thisClassAsReflectionClass = new \ReflectionClass(__CLASS__);
        return $thisClassAsReflectionClass->getConstants();
    }

    /**
     * Returns the value of the role as a string
     *
     * @return string
     */
    public function __toString()
    {
        return $this->value;
    }
}