Latest Premium Tutorial
-
· 11 mins, 2098 words · premium
Laravel Reverb Demo: Real-Time Notification on Completed Task
Some Laravel tasks are running in the background. What if you want to "listen" for those events to finish? Let's implement exactly this real-time feedback with the Reverb server.
Newest content
-
· 4 mins, 716 words
Filament: Money Columns and Storing Value in Cents
-
· 1 min, 193 words
Laravel Jetstream: Redirect After Login
-
Random Quick Laravel Tip:
Filament: Badge Columns with EnumsIf you have a set of options for radio/dropdowns in the Form, you may want to create a PHP Enum class. It will give you the benefit of re-using the same class and also automatically show colors/icons as a badge.
Before:
ProductResource.php:
public static function form(Form $form): Form{return $form->schema([// ... other fieldsForms\Components\Radio::make('status')->options(['in stock' => 'in stock','sold out' => 'sold out','coming soon' => 'coming soon',]),]);}After:
app/Enums/ProductStatus.php:
namespace App\Enums;use Filament\Support\Contracts\HasIcon;use Filament\Support\Contracts\HasLabel;use Filament\Support\Contracts\HasColor;enum ProductStatus: string implements HasLabel, HasColor, HasIcon{case IN_STOCK = 'in stock';case SOLD_OUT = 'sold out';case COMING_SOON = 'coming soon';public function getLabel(): ?string{return match ($this) {self::IN_STOCK => 'In stock',self::SOLD_OUT => 'Sold out',self::COMING_SOON => 'Coming soon',};}public function getColor(): string|array|null{return match ($this) {self::IN_STOCK => 'success',self::SOLD_OUT => 'warning',self::COMING_SOON => 'gray',};}public function getIcon(): ?string{return match ($this) {self::IN_STOCK => 'heroicon-m-pencil',self::SOLD_OUT => 'heroicon-m-eye',self::COMING_SOON => 'heroicon-m-check',};}}app/Models/Product.php
use App\Enums\ProductStatus;class Product extends Model {// ...protected $casts = ['status' => ProductStatus::class,];}ProductResource.php:
use App\Enums\ProductStatus;public static function form(Form $form): Form{return $form->schema([// ... other fieldsForms\Components\Radio::make('status')->options(ProductStatus::class),]);}It feels like a lot of work, right? But look at those methods
getLabel()
,getColor()
andgetIcon()
. Now, in the Table of the Resource, you can just use thebadge()
method, and Enum will auto-style it for you.public static function table(Table $table): Table{return $table->columns([// ... other columnsTables\Columns\TextColumn::make('status')->badge(),]);} -
· 1 min, 186 words
Filament Select with Relationship: Custom Label for titleAttribute Options
-
· 3 mins, 480 words
Filament Select with Relationship: ModifyQueryUsing for Edit Form
-
· 3 mins, 405 words
Filament Register: Automatically Assign Role from Spatie Permission
-
Premium Course: Laravel 11 Eloquent: Expert Level
-
· 2 mins, 345 words
Filament: Show/Hide Field Based on Select Value with Relationship Column
-
· 2 mins, 249 words
Filament: Show/Hide Fields based on Roles and Permissions
-
· 4 mins, 773 words
Filament Many-to-Many Select: Automatically Fill Pivot Values
-
· 1 min, 200 words
Filament: Search in Table with Accessor Column
-
· 3 mins, 413 words
Filament Table: Dynamic Column Based on other Columns with Accessor