New Laravel Project: Bon Temps
So I started a new project called 'Bon Temps'. This was originally a excercise from the course I took. There are a few requirements before this project is finished.
Requirements
- Customers can make a reservation for a specific day/time and optionally select menu's they want to order.
- Cooks can view the menu's ordered in the day with their recipes and ingredients
- Waiters can make orders
- Managers can make and manage menu's and the prices.
- Admins can do all the above
The start
I started the project by thinking about what technologies I wanted to use. This is a hobby project to learn about such technology so I choice Laravel. Laravel makes it possible to start very fast with creating what you want. Because Laravel has awesome built-in features that makes it so easy to start a project. There is the framework itself and not to mention Laravel Breeze to get a login system on a fly.
And that is what I first did. Creating a Laravel application is one command from your favorite terminal. Locally I am using WSL for all my development needs. The easiest way to get Laravel is by using the Laravel installer. Which can be installed with one command:
/bin/bash -c "$(curl -fsSL https://php.new/install/linux)"
There are also commands for mac and windows.
Then it is just one command to create a Laravel application:
laravel new myapp
This will create a project in the myapp
folder. You will get some options you can select like choice the database driver, testing framework and starter kits. For this project I choice Sqlite and Laravel Breeze with blade and alpinejs. This will give me a huge quick start.
Roles
I created a simple role-based access system. The roles are defined in a enum which I placed in the app/enums
directory:
enum Role: string
{
case ADMIN = 'admin';
case COOK = 'cook';
case CUSTOMER = 'customer';
case MANAGER = 'manager';
case WAITER = 'waiter';
}
The roles are also stored in the database in a roles
table. It is a simple table with a primary id, a user-friendly name and a key. After that I created a seeder that will populate the table with roles defined in the enum.
To be able to restrict routes to a specific role, I created a middleware. The middleware will check the roles for the user and if it doesn't contain the role, send a 403 forbidden response.
abort_if($request->user()?->roles()->where('key', $role), 403);
Crud
I created a simple crud for the ingredients. The styling is based on the Laravel Breeze components. Why start with ingredients? Well... to create a menu you need a recipe and a recipe requires ingredients. (menu -> recipe -> ingredient
). To link them together, I need 2 pivot tables because they have a many-to-many relationship. I like to create models for the pivot tables also. Only make sure to extend the model class with Pivot
instead of Model
.
And that is basically where I am right now. I'll continue this project to finish all the requirements.