More work on ordering
This commit is contained in:
24
app/Traits/NextKey.php
Normal file
24
app/Traits/NextKey.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user