<?php

namespace Sigma\Flatlab;

use Sigma\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 scopeMenu($query, $menu)
    {
        return $query->whereMenu($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);
    }
}
