tadasei / laravel-statuses
A package that provides stubs for managing status associations with models
Installs: 8
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/tadasei/laravel-statuses
Requires
- php: ^8.1.0
- illuminate/console: ^9.0|^10.0|^11.0
- illuminate/filesystem: ^9.0|^10.0|^11.0
- illuminate/support: ^9.0|^10.0|^11.0
- illuminate/validation: ^9.0|^10.0|^11.0
Requires (Dev)
- orchestra/testbench: ^8.0
- phpstan/phpstan: ^1.10
- symfony/var-dumper: ^6.4
README
This package provides stubs for statuses association to Eloquent models.
Features
- Quickly generate statuses handling utilities.
- Customize and extend generated code to fit your project's needs.
- Improve development efficiency by eliminating repetitive tasks.
Installation
You can install the package via Composer by running:
composer require tadasei/laravel-statuses --dev
Publishing statuses handling utilities
To publish statuses handling utilities, use the following command:
php artisan statuses:install
Configuring Statusable Models
To extend or define which models are considered statusable:
- Define a One-to-Many relationship with your model (one
App\Models\Status
has manyApp\Models\YourModel
). - Add your model class name to the
App\Enums\StatusableType
enum.
This allows full flexibility in defining how your application links statuses to models.
Running migrations
To create the related statuses
table, run the generated migration using the following command:
php artisan migrate
Register CRUD routes
This package generates a routes/resources/status.php
route file among its utilities. You can include this file in your routes/web.php
or routes/api.php
to enable authenticated and authorized App\Models\Status
model CRUD operations.
// in routes/api.php or routes/web.php require __DIR__ . "/resources/status.php";
Usage:
The usage is the same as any regular One-to-Many relationship:
use App\Models\{Status, User}; $status = Status::create([ "statusable_type" => User::class, "name" => "Initial status", "color" => "#858662", "is_initial" => true, "is_final" => false, ]); $user = User::first(); $status->users()->save($user);
Customization
The generated code serves as a starting point. You can customize and extend it according to your project's requirements. Modify the generated utilities as needed.
Contributing
Contributions are welcome! If you have suggestions, bug reports, or feature requests, please open an issue on the GitHub repository.
License
This package is open-source software licensed under the MIT license.