Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

pickab00's avatar

Need some help with restaurant menu management system

So the idea is pretty basic but I am not sure how it is done or how I should continue with it. Basically I am using laravel as my backend system and I wanted to allow the restaurant managers to add "menu options" to the menu items. when ever they add a new/update a menu item, they will be able to add options. Like if it is large or medium. If he wants pickles or carrots. It can be checkboxes or an input field or radio buttons. There will be many options to choose from. the managers will be adding this from the backend. Now I do not understand how my database would look like. Of course what ever table I create for menu options I will have to link it with the menu items table. That is obvious but how can I tell these things.

  • The category of the menu option. This will be something like, the size. Or the type of meat.
  • The type of option(s). Checkbox or an input field or radio buttons etc (there will be many options to choose from. one menu item may have 2 radio buttons which belongs to meat category and 3 checkboxes which belongs to size or something. It will vary.)
  • Lastly giving them name and id and other nesessary stuff. Also how can I display these (okay this will come later but for now I just want to figure out the db structure and how I could achieve this).

What I was thinking was to have a modal popup which will populate the given information above for the user. So lets say if the user clicked the "add to basket" button, they will be presented with the modal to choose size (maybe a radio button), Amount (which is an input field), extras (which maybe a checkbox). So how can I tell the db that these information/menu options are added in to the db to the specific menu item. What are the tables and relationships?

Thanks a bunch!

0 likes
2 replies
JohnBraun's avatar
Level 33

Hi @pickab00

In preparing this reply, I've driven out the code explained below with TDD. I uploaded the code to this GitHub repo. If you want, you can clone it and adjust it to your specific needs. Tests are included ("Feature" Test, Unit Tests).

I don’t know if it is the best approach, but here is how I would do it:

You'll need these 3 models:

  • MenuItem (for example "Fries”)
  • Variant (representing variations on menu items, for example sizes)
  • VariantOption (representing the options of a variation, for example: small, medium and large).

A "Menu Item" can have multiple "Variants" (like "size"). A "variant" in turn can have multiple options (like "large").

A "Variant" can be used in multiple "Menu Items", therefore a many-to-many relationship is appropriate. A "VariantOption" only belongs to a single "Variant" and a one-to-many relationship is appropriate.

// Menu Item model (MenuItem.php)
class MenuItem
{
    public function variants()
    {
        return $this->belongsToMany(Variant::class);
    }
}

// Variant model (Variant.php model)
class Variant
{
    public function options()
    {
        return $this->hasMany(VariantOption::class);
    }
}

// Variant Option (VariantOption.php model)
class VariantOption
{
    public function variant()
    {
        $this->belongsTo(Variant::class)->with('options');
    }
}

These models go with the following tables: (View the migrations)

  • menu_items table, columns: 'id', 'name', 'description'

  • variants table, columns: 'id', 'name'

  • variant_options table, columns: 'id', 'variant_id', 'option' (in which 'option' holds "large" for example)

  • menu_item_variant (pivot) table, columns: 'menu_item_id', 'variant_id'

The last table is a pivot table and facilitates the many-to-many relationship between "Menu Items" and "Variants".

Now, for example on how to interact with this system:

$menuItem = App\MenuItem::create(['name' => 'Fries', 'description' => 'Homemade fries']);
$variant = App\Variant::create(['name' => 'size']);

// Add sizes to the "size" variant
$small = new App\VariantOption(['variant_id' => $variant->id, 'option' => 'small']);
$medium = new App\VariantOption(['variant_id' => $variant->id, 'option' => 'medium']);
$large = new App\VariantOption(['variant_id' => $variant->id, 'option' => 'large']);

$variant->options()->saveMany([$small, $medium, $large]);

// Attach the variant to the MenuItem
$menuItem->variants()->attach($variant);
pickab00's avatar

@JOHNBRAUN - Hi

Sorry about the late reply. First off, thank you so much for taking the time in doing this. I can't thank you enough. I haven't got time to check this yet. But honestly, I do not think anyone would have taken their time to go this far answering a question. Again, thank you so much! I will get back to you after I am done testing.

But as far as I have read this, this is exactly what I needed and fits the requirements. The explanation was on point. Again. thank you!

1 like

Please or to participate in this conversation.