Skip to main content

Overview

The Order model represents customer orders in the restaurant management system. It stores order details including food items, quantities, pricing, and customer delivery information.

Table Information

table
string
Table Name: orders

Model Definition

namespace App\Models;

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

class Order extends Model
{
    use HasFactory;

    protected $fillable=[
        'foodname',
        'quantity',
        'price',
        'name',
        'phone',
        'address',
    ];
}

Fillable Fields

foodname
string
Name of the food item ordered
  • Database Type: string
  • Nullable: Yes
  • Example: “Grilled Salmon Deluxe”
quantity
string
Quantity of items ordered
  • Database Type: string
  • Nullable: Yes
  • Example: “2”
price
string
Total price for the order
  • Database Type: string
  • Nullable: Yes
  • Example: “51.98”
name
string
Customer name for the order
  • Database Type: string
  • Nullable: Yes
  • Example: “John Doe”
phone
string
Customer phone number
  • Database Type: string
  • Nullable: Yes
  • Example: “+1-555-0123”
address
string
Delivery address for the order
  • Database Type: string
  • Nullable: Yes
  • Example: “123 Main St, Apt 4B, New York, NY 10001”

Relationships

Database Schema

Schema::create('orders', function (Blueprint $table) {
    $table->id();
    $table->string('foodname')->nullable();
    $table->string('price')->nullable();
    $table->string('quantity')->nullable();
    $table->string('name')->nullable();
    $table->string('phone')->nullable();
    $table->string('address')->nullable();
    $table->timestamps();
});

Usage Example

// Create a new order
$order = Order::create([
    'foodname' => 'Grilled Salmon',
    'quantity' => '2',
    'price' => '51.98',
    'name' => 'John Doe',
    'phone' => '+1-555-0123',
    'address' => '123 Main St, New York, NY'
]);

// Retrieve all orders
$orders = Order::all();

// Find a specific order
$order = Order::find(1);

// Update an order
$order->update([
    'address' => '456 Oak Ave, New York, NY'
]);

Timestamps

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

Notes

The current implementation stores price and quantity as strings. Consider migrating these fields to appropriate numeric types (decimal for price, integer for quantity) for better data integrity and calculation support.

Build docs developers (and LLMs) love