Skip to main content

Overview

The Reservation model manages restaurant table reservations. It stores customer information, reservation details, and maintains a relationship with the tables being reserved.

Table Information

table
string
Table Name: reservations

Model Definition

namespace App\Models;

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

class Reservation extends Model
{
    use HasFactory;
    
    protected $fillable = [
        'name', 
        'email', 
        'phone', 
        'guest', 
        'date', 
        'time', 
        'message', 
        'table_id',
    ];
}

Fillable Fields

name
string
Customer name for the reservation
  • Database Type: string
  • Nullable: Yes
  • Example: “Jane Smith”
email
string
Customer email address
phone
string
Customer phone number
  • Database Type: string
  • Nullable: Yes
  • Example: “+1-555-0456”
guest
string
Number of guests for the reservation
  • Database Type: string
  • Nullable: Yes
  • Example: “4”
date
string
Reservation date
  • Database Type: string
  • Nullable: Yes
  • Example: “2026-03-15”
time
string
Reservation time
  • Database Type: string
  • Nullable: Yes
  • Example: “19:00”
message
string
Special requests or additional notes
  • Database Type: string
  • Nullable: Yes
  • Example: “Window seat preferred, celebrating anniversary”
table_id
unsignedBigInteger
Foreign key reference to the tables table
  • Database Type: unsignedBigInteger
  • Nullable: Yes
  • Database Constraint: Foreign key with SET NULL on delete
  • Example: 3

Relationships

belongsTo: Table

Database Schema

Schema::create('reservations', function (Blueprint $table) {
    $table->id();
    $table->string('name')->nullable();
    $table->string('email')->nullable();
    $table->string('phone')->nullable();
    $table->string('guest')->nullable();
    $table->string('date')->nullable();
    $table->string('time')->nullable();
    $table->string('message')->nullable();
    $table->unsignedBigInteger('table_id')->nullable();
    $table->foreign('table_id')
          ->references('id')
          ->on('tables')
          ->onDelete('set null');
    $table->timestamps();
});

Usage Examples

Creating a Reservation

$reservation = Reservation::create([
    'name' => 'Jane Smith',
    'email' => '[email protected]',
    'phone' => '+1-555-0456',
    'guest' => '4',
    'date' => '2026-03-15',
    'time' => '19:00',
    'message' => 'Window seat preferred',
    'table_id' => 3
]);

Querying Reservations

// Get all reservations for a specific date
$reservations = Reservation::where('date', '2026-03-15')->get();

// Get reservations with table information
$reservations = Reservation::with('table')
    ->where('date', '2026-03-15')
    ->get();

// Find reservations by customer email
$customerReservations = Reservation::where('email', '[email protected]')
    ->orderBy('date', 'desc')
    ->get();

Updating a Reservation

$reservation = Reservation::find(1);
$reservation->update([
    'time' => '20:00',
    'guest' => '5',
    'message' => 'Updated to 5 guests, window seat still preferred'
]);

Timestamps

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

Notes

Consider implementing validation to:
  • Ensure date and time fields contain valid date/time values
  • Check table availability before creating reservations
  • Validate that guest count doesn’t exceed table capacity
  • Prevent double-booking of tables at the same time

Build docs developers (and LLMs) love