DEV Community

Fazail Alam
Fazail Alam

Posted on • Originally published at blog.mfazail.com on

A quick guide for filament v3 setup and running

πŸ’‘

Filament v3 requirements: PHP 8.1+, Laravel v10.0+, Livewire v3.0+

Why this?

Some devs might be in a hurry or want to take a quick look at what Filament is and what it is used for.

Please note this guide is for new projects don't follow this guide on existing project

Let's get started 😊

After you have finished a fresh Laravel and livewire project installation you can continue to add filament to your project

composer require filament/filament:"^3.0-stable" -W
php artisan filament:install --panels

Enter fullscreen mode Exit fullscreen mode

The first command will install Filament and the second will install and set Filamnet's Panel to your project and a file will be added to the Providers Directory -

  • app/Providers/Filament/AdminPanelProvider.php

I assume that you have already connected your project to a database. After the admin panel has been setuped let's create an admin user account by running the following command:

php artisan make:filament-user

Enter fullscreen mode Exit fullscreen mode

Follow the instructions and a user will be created, now serve your application on localhost by running the following commands:

php artisan serve


npm run dev
// or 
pnpm dev

Enter fullscreen mode Exit fullscreen mode

After the dev server is up and running head over to the browser and navigate to http://localhost:8000/admin, there you will see a login screen. Enter the credentials you just entered in the terminal while creating a filament user. After successful login, you will be redirected to /admin route.

Official docs in case you want some extra.


Creating a resource πŸͺ„

In filament, resources are like sub-routes under the admin route. With one command you can instantly generate CRUD functionality for the selected Model:

  • List all records

  • Editing record

  • Viewing record

  • Creating record

  • Deleting record

I will keep the example similar to filament docs so there will less confusion, Let's create a model named Customer with its migration.

php artisan make:model Customer -m

Enter fullscreen mode Exit fullscreen mode

Update the model and migration files with the below code:

// app/Models/Customer.php
use Illuminate\Database\Eloquent\SoftDeletes;

class Customer extends Model
{
    use HasFactory, SoftDeletes;
    // add for soft delete πŸ‘†
    protected $fillable = [
        'name',
        'phone',
        'address',
    ];
}


// database/migrations/xxxx_xx_xx_xxxxxx_create_customers_table.php
return new class extends Migration
{
    public function up(): void
    {
        Schema::create('customers', function (Blueprint $table) {
            $table->id();
            $table->string("name");
            $table->string("phone");
            $table->text("address");
            $table->softDeletes();
            $table->timestamps();
        });
    }
    ...
};

Enter fullscreen mode Exit fullscreen mode

Now let's generate the resource

php artisan make:filament-resource Customer --generate --soft-deletes

Enter fullscreen mode Exit fullscreen mode

The customer is the name of the resource and will prefix or suffix to its related resource. I have added two flags which are for auto-generating form fields and table columns and for adding soft delete functionality to that resource.

If everything goes right you can see the new item in the sidebar called Customers.

Customers Page

Top comments (0)