roberts / support
Common functions used in Laravel packages
Fund package maintenance!
drewroberts
Requires
- php: ^8.4
- illuminate/contracts: ^12.26
- spatie/laravel-package-tools: ^1.92
Requires (Dev)
- guzzlehttp/guzzle: ^7.10
- guzzlehttp/promises: ^2.3
- larastan/larastan: ^3.7
- laravel/pint: ^1.24
- nunomaduro/collision: ^8.8.2
- orchestra/canvas: ^10.0.2
- orchestra/testbench: ^10.8
- orchestra/testbench-core: ^10.6.5
- orchestra/workbench: ^10.0.6
- pestphp/pest: ^4.1
- pestphp/pest-plugin-arch: ^4.0
- pestphp/pest-plugin-laravel: ^4.0
- phpstan/extension-installer: ^1.4
- phpstan/phpstan-deprecation-rules: ^2.0.3
- phpstan/phpstan-phpunit: ^2.0.7
- psy/psysh: ^0.12.10
- symfony/translation: ^7.3
This package is auto-updated.
Last update: 2025-09-13 21:35:18 UTC
README
Traits & Helper functions that are used in multiple Laravel packages & applications.
Test Function
- randomOrCreate
Model Traits for Model Edits
- HasCreator
- HasUpdater
Model Traits for Status
- HasActiveStatus
- HasApplicationStatus
- HasApprovalStatus
- HasModeratorStatus
- HasOrderStatus
- HasProcessingStatus
- HasPublishingStatus
- HasSubscriptionStatus
Installation
You can install the package via composer:
composer require roberts/support
Usage
On packages or Laravel applications that require this package, you can add the Traits to models like:
use HasCreator, HasUpdater, HasPublishingStatus;
You may only add 1 of the Status Traits since they all use the same status
database column. They are not designed to work together but to replace the functionality with the Enum structures.
Expected Columns
When using any of the Status Traits on a model, add the following format for the status
database column on your table:
status
(string (25 character max), nullable, index)
Note: Status traits automatically set appropriate default values when models are created (e.g., pending
for moderator status, active
for active status).
When using the HasCreator
and/or HasUpdater
traits on a model, add the following nullable columns to your table:
creator_id
(unsignedBigInteger, nullable)updater_id
(unsignedBigInteger, nullable)
Example migration snippet:
Schema::table('your_table', function (Blueprint $table) { $table->string('status', 25)->nullable()->index(); $table->unsignedBigInteger('creator_id')->nullable(); $table->unsignedBigInteger('updater_id')->nullable(); // Optional: add foreign keys if your users table is bigint IDs // $table->foreign('creator_id')->references('id')->on('users')->nullOnDelete(); // $table->foreign('updater_id')->references('id')->on('users')->nullOnDelete(); });
The traits automatically:
- Set
creator_id
on model creating (when an authenticated user is present). - Set
updater_id
on model saving (create and update) when an authenticated user is present.
Overriding the Auth Provider Model
By default, the creator & updater traits resolve the related user model from config('auth.providers.users.model')
.
If your application uses a different provider or model, ensure the config points to your user class. For example, in config/auth.php
:
'providers' => [ 'users' => [ 'driver' => 'eloquent', 'model' => App\Models\User::class, ], ],
Or override at runtime (e.g., inside a service provider) if needed:
config(['auth.providers.users.model' => App\Domain\Auth\User::class]);
Enums
Status traits use enums with the following values, setting the first one on model creation:
HasActiveStatus
: active, inactiveHasApplicationStatus
: pending, started, verified, applied, accepted, rejectedHasApprovalStatus
: pending, submitted, approved, rejectedHasModeratorStatus
: pending, flagged, approved, rejectedHasOrderStatus
: cart, pending, checkout, paid, shipped, delivered, canceledHasProcessingStatus
: pending, processing, completed, failedHasPublishingStatus
: draft, scheduled, published, archivedHasSubscriptionStatus
: trial, active, canceled, expired
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Credits
License
The MIT License (MIT). Please see License File for more information.