62 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			PHP
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			62 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			PHP
		
	
	
		
			Executable File
		
	
	
	
	
<?php
 | 
						||
 | 
						||
namespace kernel\modules\menu\models;
 | 
						||
 | 
						||
use Illuminate\Database\Eloquent\Model;
 | 
						||
 | 
						||
/**
 | 
						||
 * @property int $id
 | 
						||
 * @property int parent_id
 | 
						||
 * @property string icon_file
 | 
						||
 * @property string icon_font
 | 
						||
 * @property string label
 | 
						||
 * @property string url
 | 
						||
 * @property int status
 | 
						||
 * @property int priority
 | 
						||
 * @method static find($id)
 | 
						||
 */
 | 
						||
 | 
						||
class Menu extends Model
 | 
						||
{
 | 
						||
    const DISABLE_STATUS = 0;
 | 
						||
    const ACTIVE_STATUS = 1;
 | 
						||
 | 
						||
    protected $table = 'menu';
 | 
						||
    protected $fillable = ['parent_id', 'icon_file', 'icon_font', 'label', 'url', 'status', 'slug', 'priority'];
 | 
						||
    protected array $dates = ['deleted_at'];
 | 
						||
 | 
						||
    public static function labels(): array
 | 
						||
    {
 | 
						||
        return [
 | 
						||
            'label' => 'Заголовок',
 | 
						||
            'parent_id' => 'Родительский пункт меню',
 | 
						||
            'icon_file' => 'Путь к иконке',
 | 
						||
            'icon_font' => 'Иконка',
 | 
						||
            'url' => 'URL',
 | 
						||
            'status' => 'Статус',
 | 
						||
            'slug' => 'Slug',
 | 
						||
            'priority' => 'Приоритет'
 | 
						||
        ];
 | 
						||
    }
 | 
						||
 | 
						||
    public static function getChild(int $id)
 | 
						||
    {
 | 
						||
        $collection = Menu::where("parent_id", $id)->get();
 | 
						||
        if (!$collection->isEmpty()){
 | 
						||
            return $collection;
 | 
						||
        }
 | 
						||
 | 
						||
        return false;
 | 
						||
    }
 | 
						||
 | 
						||
    /**
 | 
						||
     * @return string[]
 | 
						||
     */
 | 
						||
    public static function getStatus(): array
 | 
						||
    {
 | 
						||
        return [
 | 
						||
            self::DISABLE_STATUS => "Не активный",
 | 
						||
            self::ACTIVE_STATUS => "Активный",
 | 
						||
        ];
 | 
						||
    }
 | 
						||
} |