Package Data | |
---|---|
Maintainer Username: | saritasa |
Maintainer Contact: | sergey@saritasa.com (Sergey Populov) |
Package Create Date: | 2017-04-03 |
Package Last Update: | 2022-07-18 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-05-02 15:02:12 |
Package Statistics | |
---|---|
Total Downloads: | 10,620 |
Monthly Downloads: | 25 |
Daily Downloads: | 1 |
Total Stars: | 0 |
Total Watchers: | 10 |
Total Forks: | 2 |
Total Open Issues: | 2 |
Custom Extensions for Eloquent
See https://laravel.com/docs/eloquent
Install the saritasa/eloquent-custom
package:
$ composer require saritasa/eloquent-custom
Optionally (if you want to use default migrations):
If you use Laravel 5.4 or less,
or 5.5+ with package discovery disabled,
add the PredefinedMigrationsServiceProvider service provider config/app.php
:
'providers' => array(
// ...
Saritasa\Database\Eloquent\PredefinedMigrationsServiceProvider::class,
)
then you can execute command:
php artisan vendor:publish --provider=Saritasa\Database\Eloquent\PredefinedMigrationsServiceProvider --tag=migrations
Extends Eloquent model, adds:
Example:
class User extends Entity
{
protected $defaults = [
'role' => 'user'
]
}
now if you create new user it will have role 'user' by default, if you don't provide it explicitly:
$user = new User(['name' => 'John Doe']);
$this->assertEquals('user', $user->role); // true
$admin = new User['name' => 'Mary', 'role' => 'admin');
$this->assertEquals('admin', $admin->role); // true
Global scope for Eloquent models to add sorting by name by default
Example:
class SomeModel extends Model {
...
protected static function boot()
{
parent::boot();
static::addGlobalScope(new \Saritasa\Database\Eloquent\Scopes\SortByName());
}
...
}
See CONTRIBUTING and Code of Conduct, if you want to make contribution (pull request) or just build and test project on your own.