some progress: users slugs, bookmarks page, upvotes page, design

This commit is contained in:
Doar Mihai
2026-02-14 17:06:03 +02:00
parent 67de095a03
commit cf6310dc7e
16 changed files with 419 additions and 71 deletions
+28
View File
@@ -8,6 +8,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Str;
class User extends Authenticatable
{
@@ -23,6 +24,7 @@ class User extends Authenticatable
'name',
'email',
'password',
'slug',
'avatar',
'bio',
'website',
@@ -144,4 +146,30 @@ class User extends Authenticatable
{
return $this->hasMany(Bookmark::class);
}
/**
* Generate a unique slug for the user based on their name.
*/
public static function generateUniqueSlug(string $name): string
{
$slug = Str::slug($name);
$originalSlug = $slug;
$count = 1;
// Keep appending numbers until we find a unique slug
while (static::where('slug', $slug)->exists()) {
$slug = $originalSlug . '-' . $count;
$count++;
}
return $slug;
}
/**
* Get the route key for the model.
*/
public function getRouteKeyName(): string
{
return 'slug';
}
}