osb/app/Traits/NextKey.php

24 lines
318 B
PHP
Raw Normal View History

2018-08-11 05:09:41 +00:00
<?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;
}
}