Skip to main content

Overview

The Table model represents physical tables in the restaurant. It manages table information including location type, capacity, availability status, and relationships with orders and reservations.

Table Information

table
string
Table Name: tables

Model Definition

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Table extends Model
{
    use HasFactory;

    protected $fillable = [
        'name',
        'number',
        'type',
        'status',
        'seats',
    ];
}

Fillable Fields

name
string
required
Display name for the table
  • Database Type: string
  • Nullable: No
  • Example: “Table Alpha”, “VIP-1”
number
string
required
Unique table number identifier
  • Database Type: string
  • Nullable: No
  • Unique: Yes
  • Example: “T-101”, “12”
type
enum
required
Location type of the table
  • Database Type: enum
  • Allowed Values: terraza, interior, exterior
  • Example: “interior”
status
enum
required
Current availability status of the table
  • Database Type: enum
  • Allowed Values: disponible, ocupada, reservada
  • Default: disponible
  • Example: “disponible”
seats
integer
required
Number of seats available at the table
  • Database Type: integer
  • Nullable: No
  • Example: 4

Status Values

disponible
status
Table is available for new customers or reservations
ocupada
status
Table is currently occupied by customers
reservada
status
Table has been reserved for a future booking

Type Values

terraza
location
Table located on the terrace area
interior
location
Table located inside the restaurant
exterior
location
Table located in the exterior area

Relationships

hasMany: Orders

hasOne: Reservation

Database Schema

Schema::create('tables', function (Blueprint $table) {
    $table->id();
    $table->string('name');
    $table->string('number')->unique();
    $table->enum('type', ['terraza', 'interior', 'exterior']);
    $table->enum('status', ['disponible', 'ocupada', 'reservada'])
          ->default('disponible');
    $table->integer('seats');
    $table->timestamps();
});

Usage Examples

Creating a Table

$table = Table::create([
    'name' => 'Table 1',
    'number' => 'T-001',
    'type' => 'interior',
    'status' => 'disponible',
    'seats' => 4
]);

Querying Tables

// Get all available tables
$availableTables = Table::where('status', 'disponible')->get();

// Get tables by type
$terraceTables = Table::where('type', 'terraza')->get();

// Find tables with specific capacity
$largeTables = Table::where('seats', '>=', 6)->get();

// Get occupied tables with their orders
$occupiedTables = Table::where('status', 'ocupada')
    ->with('orders')
    ->get();

Updating Table Status

// Mark table as occupied
$table = Table::where('number', 'T-001')->first();
$table->update(['status' => 'ocupada']);

// Mark table as reserved
$table->update(['status' => 'reservada']);

// Make table available again
$table->update(['status' => 'disponible']);

Complex Queries

// Get available interior tables for 4+ people
$suitableTables = Table::where('type', 'interior')
    ->where('status', 'disponible')
    ->where('seats', '>=', 4)
    ->orderBy('seats', 'asc')
    ->get();

// Get all reserved tables with reservation details
$reservedTables = Table::where('status', 'reservada')
    ->with('reservation')
    ->get();

Timestamps

  • created_at: Automatically set when the table record is created
  • updated_at: Automatically updated when the table record is modified

Best Practices

When managing table status:
  • Always update status to ocupada when customers are seated
  • Set status to reservada when a reservation is confirmed
  • Return status to disponible after customers leave
  • Consider implementing automatic status updates based on reservation times

Build docs developers (and LLMs) love