limanweb/eloquent-extensions is a Laravel package for extensions for laravel eloquent\model.
It currently has 0 GitHub stars and 6.121 downloads on Packagist (latest version v1.2.1).
Install it with composer require limanweb/eloquent-extensions.
Discover more Laravel packages by limanweb
or browse all Laravel packages to compare alternatives.
Last updated
Extensions for Laravel Eloquent\Model and other classes
created_at, updated_at, deleted_at by authorized user IDRun:
composer require "limanweb/eloquent-extension"
Add into create or update table migration fields for userstamps created_at, updated_at and deleted_at.
For examle modify CreateUsersTable migration.
class CreateUsersTable extends Migration
{
public function up()
{
Schema::create('users', function (Blueprint $table) {
...
// add userstamps fields
$table->bigInteger('created_by')->nullable();
$table->bigInteger('updated_by')->nullable();
// if SoftDeletes trait will be used in model then add deleted_by field
// $table->bigInteger('deleted_by')->nullable();
});
}
...
}
In the model you must:
$userstamps with true value...
use Limanweb\EloquentExt\Models\Concerns\HasUserstamps; // (1) declare
class User extends Authenticatable
{
use Notifiable;
use HasUserstamps; // (2) use trait in the model
public $userstamps = true; // (3) enable userstamps
...
}
The created_by and updated_by fields in your model will now be populated in the same way as the timestamp fields when you create and update the model. If your model uses SoftDeletes traite, will also be processed field, deleted_by.
In the model you must:
false...
use Limanweb\EloquentExt\Models\Concerns\HasCompositePrimaryKey; // (1) declare trait
class Example extends Model
{
use HasCompositePrimaryKey; // (2) use trait in the model
public $incrementing = false; // (3)
protected $primaryKey = ['part1', 'part2']; // (4)
...
}
Example of using
>>> $m = Example::find([65, 275]);
=> App\Example {#3837
part1: 65,
part2: 275,
message: "record 65:275",
}
>>> $m->getKey();
=> [
65,
275,
]