- What is abather/spatie-laravel-model-states-actions?
- It is a Composer package that adds Filament actions for models using spatie/laravel-model-states. It lets you display or add actions in your views based on the current model state. The package depends on Spatie's Laravel Model States package and extends its state classes with Filament-specific behavior.
- How do I install abather/spatie-laravel-model-states-actions?
- Install it with Composer using composer require abather/spatie-laravel-model-states-actions. Then follow the spatie/laravel-model-states documentation for defining your states. Each state class should extend Abather\SpatieLaravelModelStatesActions\State instead of the base Spatie state class.
- Which Laravel and Filament versions are supported?
- The README excerpt does not list explicit Laravel or Filament version constraints. You should check the package's composer.json on Packagist or GitHub for the exact requirements. Because it depends on spatie/laravel-model-states, your Laravel version must also satisfy that package's constraints.
- How do I define states for this package?
- Define your state classes as you would with spatie/laravel-model-states, but extend Abather\SpatieLaravelModelStatesActions\State. In each abstract state class, implement the static config method and return a StateConfig using parent::config() with default and allowTransition calls. The README example shows configuring default, paid, and failed transitions.
- How does authorization work for state actions?
- You can set a protected static ?string $ability property on a state class, such as 'cancel'. The package uses that ability name to check the related model policy, for example OrderPolicy, to decide whether the user can change to that state. It also checks whether the transition is allowed using canTransitionTo from Spatie's package.
- Can I skip authorization for a state action?
- Yes. Override the $skip_authorization attribute and set it to true on the state class. This bypasses the policy ability check for that state action. Keep in mind that the package still checks whether the transition is allowed via canTransitionTo.
- Does the package check allowed state transitions?
- Yes. The package checks whether a model can transition to the target state using canTransitionTo, which comes from spatie/laravel-model-states. This means your StateConfig allowTransition rules still control which actions are valid. Authorization is an additional check on top of the transition rules.
- How do I customize the action icon and color?
- Override the protected static ?string $color and $icon attributes on your state class. For example, set $color to 'danger' and $icon to a Heroicon name such as 'heroicon-o-cursor-arrow-rays'. The README directs you to Filament's documentation for valid icon and color values.
- How can I test state actions in my Laravel application?
- The README does not document package-specific testing helpers. You can test state actions using normal Laravel and Filament testing approaches, including policy checks and Spatie state transition assertions. Verify that canTransitionTo returns the expected result and that the policy ability allows or denies the action.
- Is this package suitable for production, and what are the alternatives?
- It is a small wrapper around spatie/laravel-model-states, so production suitability depends on its maintenance status and your version constraints. Check Packagist downloads, GitHub issues, and recent commits before adopting it. As an alternative, you can build Filament actions manually on top of Spatie's state and transition APIs without this package.