Building a Gym Management App with Laravel, Filament, Herd, and Blueprint
Published: 2024-06-09 11:54:56

Hello friends,

I recently took on the challenge of building a gym management application. Using Laravel along with some fantastic tools like Filament, Herd, and Blueprint, I was able to create a robust app in no time. If you find documentation hard to follow or just want a more guided experience, this post is for you. I'll walk you through everything step-by-step. Let's dive in!

## Setting Up Your Environment with Herd

First things first, let's get our development environment ready with Herd. Herd makes setting up Laravel projects a breeze, so you can get to coding faster.

1. **Download and Install Herd:** Head over to [Herd's official site](https://herd.laravel.com/) and follow the instructions to install it.
2. **Create a New Laravel Project:** Open your terminal and run:
    ```bash
    laravel new project-name
    ```
   Replace `project-name` with your desired project name.

## Installing Filament

Filament is an awesome admin panel for Laravel applications. It gives you a beautiful, easy-to-use interface to manage your app's data.

1. **Navigate to Your Project Directory:**
    ```bash
    cd project-name
    ```
2. **Install Filament:** Run the following command to install Filament:
    ```bash
    composer require filament/filament:"^3.2" -W
    ```
3. **Set Up Filament:** After installation, set it up with:
    ```bash
    php artisan filament:install --panels
    ```
4. **Start the Development Server:**
    ```bash
    php artisan serve
    ```
   Now, you can access the admin panel at `http://localhost/admin`.

5. **Create an Admin User:**
    ```bash
    php artisan make:filament-user
    ```
   Follow the prompts to set up a username and password.

## Accelerating Development with Blueprint

Blueprint lets you define your application's models, controllers, and more using simple YAML files. This can save you a ton of time.

1. **Install Blueprint:**
    ```bash
    composer require -W --dev laravel-shift/blueprint
    ```
2. **Create a New Blueprint Draft:**
    ```bash
    php artisan blueprint:new
    ```

Here's an example `draft.yaml` file for our gym management application:

```yaml
models:
  Member:
    id: id
    name: string:255
    email: string:255 unique
    phone: string:20
    address: string:255
    membership_start_date: date
    membership_end_date: nullable date
    membership_type_id: foreignId:constrained:cascade
    relationships:
      belongsTo: membership_type
      hasMany: payments, invoices

  MembershipType:
    id: id
    name: string:255
    description: text
    price: decimal:8,2
    duration_months: integer
    relationships:
      hasMany: members

  Payment:
    id: id
    member_id: foreignId:constrained:cascade
    amount: decimal:8,2
    payment_date: date
    payment_method: string:50
    relationships:
      belongsTo: member

  Invoice:
    id: id
    member_id: foreignId:constrained:cascade
    amount: decimal:8,2
    due_date: date
    paid: boolean
    relationships:
      belongsTo: member
```

3. **Build Your Application:**
    ```bash
    php artisan blueprint:build
    ```
   This command will generate the necessary models, migrations, and more based on your `draft.yaml`.

4. **Run the Migrations:**
    ```bash
    php artisan migrate
    ```

## Creating Filament Resources

Filament makes it super easy to generate resource management interfaces. Let's create resources for our models.

1. **Generate Resources:**
    ```bash
    php artisan make:filament-resource MemberResource --generate
    php artisan make:filament-resource PaymentResource --generate
    php artisan make:filament-resource InvoiceResource --generate
    ```

## Wrapping Up

And there you have it! Using Herd, Filament, and Blueprint, I was able to quickly build a functional gym management application. These tools made the process smooth and enjoyable, turning what could have been a tedious task into a fun project.

If you're looking to speed up your Laravel development and build powerful applications with ease.


Follow me on [Twitter](https://twitter.com/hshahzadaheer), [LinkedIn](https://www.linkedin.com/in/hassanshahzadaheer), and [Instagram](https://www.instagram.com/hassan_aheer) for more insights and updates!