id = self::NextId(); }); static::saved(function($model) { if ($model->wasRecentlyCreated) { if (! defined(get_class($model).'::RECORD_ID')) throw new \Exception('Missing record_id const for '.get_class($model)); $mo = Module::where('name',$model::RECORD_ID)->firstOrFail(); if (! $mo->record) { $mo->record = new Record; $mo->record->module_id = $mo->id; $mo->record->site_id = 1; // @todo } $mo->record->id = $model->id; $mo->record->save(); } }); } public static function NextId() { return (new self)->max('id')+1; } }