FilamentF
Filament13mo ago
sohail

How to Structure Code for Filament Modules in Livewire?

I am using all Filament modules in Livewire directly, not the Panel Builder. My goal to make the main component cleaner and lighter by breaking down functionality into smaller parts. Here are the two approaches I am considering:

Approach 1: Using Traits


  • Break down actions and forms into traits to keep the main Livewire component focused on its primary responsibilities.
  • The traits encapsulate logic related to actions and forms for better code clarity.
File Structure:
app/
├── Http/
│   ├── Livewire/
│   │   ├── Organization/
│   │   │   ├── Index.php
│   │   │   ├── Traits/
│   │   │   │   ├── Actions.php
│   │   │   │   ├── Forms.php


---

Approach 2: Using Classes


  • Encapsulate each action and bulk action into its own class for better organization.
  • The classes are grouped logically in directories to separate concerns and keep the main component light.
File Structure:
app/
├── Http/
│   ├── Livewire/
│   │   ├── Organization/
│   │   │   ├── Index.php
│   │   │   ├── Actions/
│   │   │   │   ├── Edit.php
│   │   │   │   ├── Restore.php
│   │   │   │   ├── Delete.php
│   │   │   │   ├── ForceDelete.php
│   │   │   ├── BulkActions/
│   │   │   │   ├── BulkRestore.php
│   │   │   │   ├── BulkDelete.php
│   │   │   │   ├── BulkForceDelete.php


Which approach is more used in the filament Community
Was this page helpful?