24 lines
318 B
PHP
24 lines
318 B
PHP
<?php
|
|
|
|
/**
|
|
* Works out the next ID to use for an Eloquent Table.
|
|
*/
|
|
namespace App\Traits;
|
|
|
|
trait NextKey
|
|
{
|
|
public static function boot()
|
|
{
|
|
parent::boot();
|
|
|
|
static::creating(function($model)
|
|
{
|
|
$model->id = self::NextId();
|
|
});
|
|
}
|
|
|
|
public static function NextId()
|
|
{
|
|
return (new self)->max('id')+1;
|
|
}
|
|
} |