Currently Available: Need a skilled Software Developer for your next project?
Categories
Laravel

Building a Custom Blog with Laravel, Livewire, and Filament

A Laravel blog has two connected interfaces: a public site where readers browse published posts, and an admin panel where authorized users manage content. Laravel handles the core features, including routes, database records, and user permissions. Livewire uses PHP and Blade to make pages respond to user actions. Filament provides admin tools such as post-management screens and dashboard charts.

Episode 19 of Build Blog with Laravel, Livewire & Filament shows two Filament dashboard widgets: a user count and a chart of posts published each month. The episode uses Laravel 10, Livewire 3, and Filament 3. To build a blog with these features, decide which posts readers can see, who can edit them, and which posts the chart counts. A Filament resource is an admin interface for managing a type of database data, such as posts. A widget is a dashboard component, such as a count card or chart.

Choose versions before following the episode

Use the episode as an example for specific software versions. Its description names Laravel 10, Livewire 3, and Filament 3. Commands and code from the episode may not match projects using newer major versions. Check the versions recorded in composer.lock, then follow the documentation for those versions. Filament’s version support policy lists support dates for each major release and notes that support for required dependencies can vary.

Laravel, Livewire, and Filament do different jobs. Laravel handles routes and database records. It also manages sign-in, permissions, and file storage. Livewire sends a request to the server when a user interacts with a page. This lets developers build admin forms and filters, and each interaction depends on a server request. Filament builds on Livewire to provide admin screens and dashboard components. Its dashboard widgets include statistics, charts, and tables.

Define posts and their publication rules

Start with a database entry for each post. Store its title, unique slug, body, and excerpt. Also record its status, publication time, and author. If needed, store the path to its featured image. A slug is the readable part of a post URL, such as laravel-blog-design. A database rule that requires unique slugs prevents two posts from using the same one, even when editors submit similar titles.

Store a publication timestamp separately from the record’s creation time. A post created today and scheduled for next week is not published today. For the public blog, show only posts with a published status and a published_at time that is not in the future. Sort by publication time and paginate the results. Apply the same visibility rule to individual post pages so readers cannot open a draft by guessing its slug.

For example, a Laravel model scope can keep the listing rule in one place:

public function scopePubliclyVisible(Builder $query): Builder
{
    return $query
        ->where('status', 'published')
        ->whereNotNull('published_at')
        ->where('published_at', '<=', now());
}

Use that scope for both the listing and detail queries. When an editor changes a title, decide whether the slug should stay fixed or update; silently changing a published slug can break existing links.

Build the admin panel around the post model

Create a Filament resource for posts so editors can list, create, and update records in the admin panel. Add form fields for the title, slug, body, excerpt, status, publication time, and featured image. The resource gives editors a structured way to manage posts, while the public blog can use its own layout and navigation.

Require a title and body. Set length limits for the slug and make sure it is unique. Check that the publication time is valid. Limit image uploads by type and size. Livewire’s validation tools use Laravel’s validation features. Check the data before saving, even if the form also checks fields as editors change them.

Authentication identifies who signed in; authorization determines what that person can do. A logged-in user should not automatically gain permission to manage every post. Use Laravel policies and gates to express rules such as whether an editor can update another author’s post or access the admin dashboard.

Make the monthly chart count the right posts

For a chart labeled “posts published per month,” decide exactly what it counts. Use each post’s published_at date, include only posts that meet the publication rule, and choose a date range, such as the last 12 months or all available history. Also decide whether to show months with no posts as zero. These choices affect the information readers get, even if the charts look similar.

The database engine determines which query expression can group post timestamps by calendar month. Use an expression supported by the project’s database and test it. Choose the timezone for the chart, too. A post published near midnight can fall in different calendar months depending on the timezone used.

Episode 19 describes a user-count widget and a monthly published-post chart, but its available description does not specify the chart’s time range, timezone, or treatment of empty months. Define those choices in the dashboard label or accompanying text. For example, “Published posts per month, last 12 months” tells an administrator more than “Posts.”

Handle uploaded images and test the publishing path

Livewire stores an uploaded file temporarily while the editor submits the form. The code then saves it to the configured storage disk, which is the storage location for uploaded files. Set allowed image types and size limits. Decide whether the storage disk makes files publicly available, and remove an old image when an editor replaces it. For temporary uploads backed by S3, Livewire’s upload documentation recommends automatically deleting temporary files older than 24 hours.

Test the rules that protect the public site and admin panel as well as successful form submissions. Check that drafts and posts scheduled for the future stay hidden, and that a published post opens at its slug URL. Submit invalid form data and confirm that the form returns validation errors. Check that unauthorized users cannot enter the panel or edit posts. Verify that the chart counts publication dates rather than creation dates, and that uploaded images are saved to and displayed from the intended storage disk. Livewire provides testing helpers for checking validation, authorization failures, redirects, and rendered output.

What I'm building

Delegate tasks. Get software.

Give Vroni a GitHub issue, bug report, spec, or rough idea. It reads the repo, plans the change, writes code, runs checks, and works toward a review-ready pull request.

Take a look at vroni.com

Email updates

Usually a new article and a few links I found interesting.

No spam. Unsubscribe with one click.

Leave a Reply

Your email address will not be published. Required fields are marked *