Video Version of the Lesson
[Only for premium members]
[Only for premium members]
[Only for premium members]
In the process of while we're building simple tables, you got already familiar with three types of actions:
In this lesson, we will look at how to create custom actions for all those cases and more.
Let's try to add another button to the Orders table, like "Mark as Complete," which would require confirmation and would change the status of the order.
Migration:
Schema::table('orders', function (Blueprint $table) { $table->boolean('is_completed')->default(false);});
Also, we make it fillable:
app/Models/Order.php:
class Order extends Model{ use HasFactory; protected $fillable = [ 'user_id', 'product_id', 'price', 'is_completed', ];
Now, here's what action we can add to the table:
app/Filament/Resources/OrderResource.php:
return $table ->columns([ // ... ]) ->actions([ Tables\Actions\EditAction::make(), Tables\Actions\Action::make('Mark Completed') ->requiresConfirmation() ->icon('heroicon-o-check-badge') ->hidden(fn (Order $record) => $record->is_completed) ->action(fn (Order $record) => $record->update(['is_completed' => true])), ])
Here's the visual result:
Pretty sure that the code above is self-explanatory, but here are...