Mastering CRUD in Laravel with Filament: Step-by-Step Guide

TechnologiesNinja > Blog > Uncategorized > Mastering CRUD in Laravel with Filament: Step-by-Step Guide

Mastering CRUD in Laravel with Filament: Step-by-Step Guide

Filament is one of the best admin panel solutions for Laravel, offering a powerful UI to manage CRUD (Create, Read, Update, Delete) operations. It simplifies handling application data and integrates seamlessly with Laravel.

What is Filament?

Filament is a Laravel admin panel package that provides a beautiful interface for managing data. Unlike traditional admin panels, Filament is:

  • ✅ Fast & easy to set up
  • ✅ Built using Livewire for a dynamic experience
  • ✅ Customizable & extendable
  • ✅ Compatible with Laravel’s policies and permissions

Prerequisites

Before we get started, make sure you have:

  • Laravel 10+
  • PHP 8.1+
  • Composer
  • A configured database (MySQL, PostgreSQL, SQLite, etc.)

Step 1: Install Filament in Laravel

composer require filament/filament

Now, publish Filament assets:

php artisan filament:install

Create an admin user:

php artisan make:filament-user

Access the Filament dashboard:

http://your-app.test/admin

Step 2: Create a Model and Migration

php artisan make:model Post -m

Modify the migration file:

public function up() {
    Schema::create('posts', function (Blueprint $table) {
        $table->id();
        $table->string('title');
        $table->text('content');
        $table->timestamps();
    });
}

Run the migration:

php artisan migrate

Step 3: Generate a Filament CRUD Resource

php artisan make:filament-resource Post

Step 4: Configure Filament Resource

Edit app/Filament/Resources/PostResource.php:

public static function form(Forms\Form $form): Forms\Form {
    return $form->schema([
        Forms\Components\TextInput::make('title')->required()->maxLength(255),
        Forms\Components\Textarea::make('content')->required(),
    ]);
}

Step 5: Test Your Filament CRUD

Visit:

http://your-app.test/admin/posts

Step 6: Customizing the Admin Panel

1. Change Page Titles

public static function getModelLabel(): string {
    return 'Post';
}

2. Add a Rich Text Editor

Replace:

Forms\Components\Textarea::make('content')->required(),

With:

Forms\Components\RichEditor::make('content')->required(),

Conclusion

With Filament, building a CRUD system in Laravel is super easy. You now have a fully functional admin panel to manage posts.

Frequently Asked Questions

1. Can I use Filament in an existing Laravel project?

Yes! Filament can be added to any existing Laravel application without affecting your current setup.

2. Does Filament support API-based CRUD?

No, Filament is designed for admin panels. For APIs, use Laravel API Resources.

3. Can I customize Filament’s UI?

Absolutely! Filament supports themes, layouts, and component styling.

Share This Guide!

If this guide helped you, share it with your developer friends. Happy coding! 🚀

How to Add This Blog to WordPress?

  • WordPress Classic Editor – Copy & paste this content directly.
  • WordPress Block Editor (Gutenberg) – Use a Custom HTML block for the code snippets.

Leave A Comment

All fields marked with an asterisk (*) are required