ludo237 / laravel-traits
Useful set of Laravel traits
Installs: 1 212
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Forks: 0
pkg:composer/ludo237/laravel-traits
Requires
- php: ^8.2
- illuminate/support: 11.x | 12.x
Requires (Dev)
- fakerphp/faker: ^1.11
- larastan/larastan: ^v3.1.0
- laravel/framework: 11.x | 12.x
- laravel/pint: ^1.14
- mockery/mockery: ^1.6
- orchestra/testbench: ^v9.11.0
- pestphp/pest: ^v3.7
README
A set of useful traits for Laravel.
Why
Laravel is a great framework and Eloquent is a piece of art in terms of ActiveRecord ORM but it lacks some useful quirks and features that I decided to integrated trough a set of Traits.
What is a trait?
In PHP A trait is a a mechanism for code reuse in single inheritance languages such as PHP. A Trait is intended to reduce some limitations of single inheritance by enabling a developer to reuse sets of methods freely in several independent classes living in different class hierarchies. The semantics of the combination of Traits and classes is defined in a way which reduces complexity,and avoids the typical problems associated with multiple inheritance and Mixins. Source
How to use this package
Simple enough, just grab it from composer composer require ludo237/laravel-traits and it's done. Now you can use the traits inside your eloquent models or wherever you needs them
What is included
With time things can change current traits are:
Bannableinject logic into models to interact with abanned_atcolumn.CanBeActivateadd logic to a model in order to activate/deactivate it using a timestamp columnExposeTablePropertiesit allows the model to expose publicly the table name, the primary key name and his type.HasSlugautomatically creates the logic behind aslugcolumn for your model.InteractsWithApiautomatically set the api_key for the current model following Laravel standards.OwnedByUserAutomatically set the current model as owned by the User modelBenchmarkableStart/Stop a timer to benchmark your Artisan Commands
How to Contribute
Please see the contribute file for more information