Eloquent Model wrapper with extended functionality
MIT License
Eloquent Model wrapper with extended functionality.
You can install the package via composer:
composer require sfneal/models
AbstractModel
, AbstractPivot
, & AbstractAuthenticatable
can be used as parent classes the same way Eloquent's Model
, Pivot
& Authenticatable
can be used. AbstractModel
uses Sfneal\Builders\QueryBuilder
as the default Eloquent Query Builder (see sfneal/builders.
class YourModel extends AbstractModel
{
protected $table = 'your_model';
protected $primaryKey = 'your_model_id';
protected $fillable = [
'your_model_id',
//
];
}
Models that extend the AbstractModel
class will have access to a variety of public access to a variety of methods that extends many of Models
existing functionality's.
// Create a new Model record
$model = YourModel::query()->create($data);
// returns true
$model->wasCreated();
// Update the Model
$model->update([
'some_attribute' => 'blue'
]);
// returns false
$model->wasCreated();
// returns true
$model->wasUpdated();
Add the custom QueryBuilder to any Eloquent model by overwriting the built-in newEloquentBuilder() & query() methods.
use Illuminate\Database\Eloquent\Builder;
use Sfneal\Builders\QueryBuilder;
class ExampleModel extends Model
{
/**
* Query Builder.
*
* @param $query
* @return QueryBuilder
*/
public function newEloquentBuilder($query)
{
return new QueryBuilder($query);
}
/**
* Query Builder method for improved type hinting.
*
* @return QueryBuilder|Builder
*/
public static function query()
{
return parent::query();
}
}
composer test
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.
This package was generated using the PHP Package Boilerplate.