'int', 'group_id' => 'int', 'restaurant_id' => 'int', 'ordering' => 'int', 'is_deletable' => 'int' ]; protected $guarded = []; /*protected $fillable = [ 'restaurant_id', 'name', 'ordering', 'is_deletable', 'notes' ];*/ /** * Relación con el restaurante */ public function restaurant() { return $this->belongsTo(Restaurant::class); } /** * Relación many-to-many con mesas */ public function tables() { return $this->belongsToMany(Table::class, 'table_ttag', 'ttag_id', 'table_id'); } public function group() { return $this->belongsTo(TTagGroup::class, 'group_id'); } /** * Obtener etiquetas por restaurante */ public static function getByRestaurant($restaurant_id) { return static::where('restaurant_id', $restaurant_id) ->orderBy('ordering', 'ASC') ->orderBy('name', 'ASC') ->get(); } /** * Crear etiqueta con valores por defecto */ public static function createTag($data, $restaurant_id) { $defaults = [ 'restaurant_id' => $restaurant_id, 'ordering' => 999, 'is_deletable' => 1, 'notes' => '', 'date_created' => date('Y-m-d H:i:s'), 'date_modified' => date('Y-m-d H:i:s') ]; $data = array_merge($defaults, $data); return static::create($data); } /** * Verificar si la etiqueta puede ser eliminada */ public function canBeDeleted() { return $this->is_deletable == 1; } }