<?php

namespace Sargilla\Flatlab4;

use Sargilla\Flatlab4\Flatlab4Menu as Menu;

use Illuminate\Database\Eloquent\Model;

class Flatlab4Menu 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);
    }
}
