Apps Artificial Intelligence CSS DevOps Go JavaScript Laravel Linux MongoDB MySQL PHP Python Rust Svelte Vue

Building an Article CRUD with Laravel and Filament Admin Panel

2 min read .
Building an Article CRUD with Laravel and Filament Admin Panel

Laravel provides a productive foundation for modern PHP applications, and Filament can add a powerful admin panel with generated forms, tables, and CRUD pages.

In this tutorial, we will create a Laravel project and build an Article CRUD resource with Filament.

1. Create a New Laravel Project

composer create-project --prefer-dist laravel/laravel website

The final argument, website, is the project directory name. Change it if you want a different project name.

Enter the directory:

cd website

2. Configure the Database

A fresh Laravel project may be configured for SQLite depending on the installed Laravel version and project template. To use MySQL, update .env with values appropriate for your environment:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=website
DB_USERNAME=app_user
DB_PASSWORD=your-secure-password

Avoid using a privileged MySQL account such as root for an application in production.

Run the initial migrations:

php artisan migrate

3. Install Filament

Install Filament:

composer require filament/filament

Install a panel:

php artisan filament:install --panels

Create a user who can sign in to the panel:

php artisan make:filament-user

Start the local development server:

php artisan serve

You can then open the Filament panel, which is commonly mounted at /admin unless you changed its configuration.

4. Generate a User Resource (Optional)

To experiment with generated resources:

php artisan make:filament-resource User --generate

Filament can inspect the model and generate a starting form and table configuration that you can customize.

5. Create the Article Model and Migration

php artisan make:model Article -m

Edit the generated migration:

Schema::create('articles', function (Blueprint $table) {
    $table->id();
    $table->string('title');
    $table->text('content');
    $table->string('slug')->unique();
    $table->string('image')->nullable();
    $table->timestamps();
});

Run the migration:

php artisan migrate

6. Configure Mass Assignment Safely

Do not disable Eloquent mass-assignment protection globally just to make an admin form work. Instead, explicitly define which fields may be mass assigned on the model:

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Article extends Model
{
    protected $fillable = [
        'title',
        'content',
        'slug',
        'image',
    ];
}

This keeps the model’s writable fields intentional and easier to audit.

7. Generate the Article Resource

php artisan make:filament-resource Article --generate

Filament creates a resource structure containing CRUD pages plus form and table definitions. Review the generated code rather than treating it as final: configure field validation, file-upload storage, authorization, table columns, and any slug-generation behavior your application needs.

8. Result

At this point you have:

  • A Laravel application.
  • A Filament admin panel.
  • An admin user for local testing.
  • An articles table and Article model.
  • A generated Filament resource that can be customized into a full Article CRUD workflow.

Conclusion

Laravel and Filament can reduce the amount of repetitive code required for internal dashboards and content-management interfaces. Generated resources are a useful starting point, but production applications should still define authorization, validation, mass-assignment rules, storage behavior, and business logic explicitly.

Related Posts

chevron-up