<?php

namespace Sargilla\FlatLab;

use Sargilla\FlatLab\FlatLabMenu as Menu;

use Illuminate\Database\Eloquent\Model;

class FlatLabMenu extends Model
{
    protected $guarded = [];
    protected $table = 'menus';

    public function padre()
    {
        return $this->belongsTo(Menu::class,'padre_id');
    }
    public function hijos()
    {
        return $this->hasMany(Menu::class,'padre_id');
    }
    public static function scopeItems($query, $menu)
    {
        return $query->where('menu', $menu);
    }
    public function scopeRaiz($query)
    {
        return $query->where('padre_id', 0);
    }
    public function scopeOrdenar($query, $direccion = 'asc')
    {
        return $query->orderBy('orden', $direccion);
    }
    public function tieneHijos()
    {
        return count($this->hijos);
    }
}
