auto create an organisation for a user when they sign up
This commit is contained in:
@@ -6,6 +6,7 @@ use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class Organisation extends Model
|
||||
{
|
||||
@@ -29,4 +30,14 @@ class Organisation extends Model
|
||||
{
|
||||
return $this->hasMany(Application::class);
|
||||
}
|
||||
|
||||
public static function createUniqueSlug(string $name): string
|
||||
{
|
||||
$slug = Str::slug($name);
|
||||
$count = 2;
|
||||
while (Organisation::where('slug', $slug)->exists()) {
|
||||
$slug = Str::slug($name) . '-' . $count++;
|
||||
}
|
||||
return $slug;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user