Overview
The menu management system allows admins and chefs to create, update, and organize food items with comprehensive details including nutritional information, pricing, and categorization.Food Model
The Food model represents individual menu items with all their attributes.app/Models/Food.php
Food Attributes
The name of the food item displayed on menus
Price of the food item
Path to the food item image stored in storage
Detailed description of the food item
List of ingredients used in the dish
Protein content in grams for nutritional information
Caloric content of the dish
Serving size (e.g., “Regular”, “Large”, “500g”)
Foreign key linking to the categories table
Category System
Food items are organized into categories for better navigation and filtering.app/Models/Category.php
Categories help organize menu items (e.g., “Appetizers”, “Main Courses”, “Desserts”, “Beverages”) and enable filtered browsing for customers.
Food Controller
The FoodController handles all CRUD operations for menu items with role-based access control.List All Foods
app/Http/Controllers/Admin/FoodController.php
Eager Loading Performance
Eager Loading Performance
The
with('category') method uses eager loading to prevent N+1 query problems. This loads all related categories in a single query, significantly improving performance when displaying multiple food items.Create New Food Item
app/Http/Controllers/Admin/FoodController.php
Update Existing Food Item
app/Http/Controllers/Admin/FoodController.php
Image Management: The system automatically deletes old images when updating to prevent storage bloat. The
ImageService handles secure file storage and deletion.Delete Food Item
app/Http/Controllers/Admin/FoodController.php
Image Service
The system uses a dedicatedImageService for consistent image handling:
- Store Image
- Delete Image
Public Menu Display
Customers can browse the menu without authentication:app/Http/Controllers/HomeController.php
Food Detail View
app/Http/Controllers/HomeController.php
Route model binding automatically fetches the Food model:
Route::get('/infocomida/{food}', ...)Access Control
Menu management routes are protected by role middleware:routes/web.php
- ✅ Admin: Full access (create, read, update, delete)
- ✅ Chef: Full access (create, read, update, delete)
- ❌ Mesero: No access to food management
- ❌ Customers: Read-only access through public routes
Form Validation
The system uses Form Request classes for validation:StoreFoodRequest
StoreFoodRequest
Custom validation rules for creating new food items:
title: required, string, max 255 charactersprice: required, numeric, min 0image: required, image file, max 2MBcategory_id: required, exists in categories tableproteins: nullable, numericcalories: nullable, integer
UpdateFoodRequest
UpdateFoodRequest
Similar to StoreFoodRequest but with optional image:
- All fields same as create
image: nullable (only required if changing)
Best Practices
- Always Use Eager Loading: Load categories with
->with('category')to avoid N+1 queries - Image Cleanup: Delete old images before storing new ones to manage storage
- Pagination: Use
paginate()for large menus to improve performance - Category Organization: Group similar items together for better UX
- Nutritional Data: Include proteins and calories for health-conscious customers
- Validation: Use Form Requests for consistent validation rules