osb/app/Traits/NextKey.php
2018-08-11 15:21:15 +10:00

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;
}
}