auto create an organisation for a user when they sign up

This commit is contained in:
2025-03-27 13:34:22 +00:00
parent 2f5536342b
commit a9b69d1a0e
2 changed files with 27 additions and 0 deletions

View File

@@ -3,6 +3,8 @@
namespace App\Models;
// use Illuminate\Contracts\Auth\MustVerifyEmail;
use App\Enums\OrganisationRole;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
@@ -12,6 +14,20 @@ class User extends Authenticatable
/** @use HasFactory<\Database\Factories\UserFactory> */
use HasFactory, Notifiable;
public static function boot()
{
parent::boot();
static::created(function (User $user) {
$organisation = Organisation::create([
'name' => $user->name,
'slug' => Organisation::createUniqueSlug($user->name),
'owner_id' => $user->id,
]);
$organisation->members()->attach($user, ['role' => OrganisationRole::Admin]);
});
}
protected $fillable = [
'name',
'email',