ludo237 / laravel-traits
Useful set of 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:
Bannable
inject logic into models to interact with abanned_at
column.CanBeActivate
add logic to a model in order to activate/deactivate it using a timestamp columnExposeTableProperties
it allows the model to expose publicly the table name, the primary key name and his type.HasSlug
automatically creates the logic behind aslug
column for your model.InteractsWithApi
automatically set the api_key for the current model following Laravel standards.OwnedByUser
Automatically set the current model as owned by the User modelBenchmarkable
Start/Stop a timer to benchmark your Artisan Commands
How to Contribute
Please see the contribute file for more information