diff --git a/app/Http/Controllers/Auth/RegisteredUserController.php b/app/Http/Controllers/Auth/RegisteredUserController.php index 44a3930..bb800a1 100644 --- a/app/Http/Controllers/Auth/RegisteredUserController.php +++ b/app/Http/Controllers/Auth/RegisteredUserController.php @@ -9,6 +9,7 @@ use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Hash; +use Illuminate\Support\Str; use Illuminate\Validation\Rules; use Illuminate\Validation\ValidationException; use Illuminate\View\View; @@ -36,9 +37,17 @@ class RegisteredUserController extends Controller 'password' => ['required', 'confirmed', Rules\Password::defaults()], ]); + $base = Str::slug($request->name); + $slug = $base; + $i = 1; + while (User::where('slug', $slug)->exists()) { + $slug = $base . '-' . $i++; + } + $user = User::create([ - 'name' => $request->name, - 'email' => $request->email, + 'name' => $request->name, + 'slug' => $slug, + 'email' => $request->email, 'password' => Hash::make($request->password), ]); diff --git a/app/Http/Controllers/CompareController.php b/app/Http/Controllers/CompareController.php index 3bb3756..8c891d3 100644 --- a/app/Http/Controllers/CompareController.php +++ b/app/Http/Controllers/CompareController.php @@ -9,7 +9,7 @@ class CompareController extends Controller public function show(User $user) { if (auth()->id() === $user->id) { - return redirect()->route('users.show', $user->username); + return redirect()->route('users.show', $user->slug); } $myGames = auth()->user()->library()->with('game')->get()->keyBy('game_id'); diff --git a/app/Http/Controllers/FollowController.php b/app/Http/Controllers/FollowController.php index df66872..af94e70 100644 --- a/app/Http/Controllers/FollowController.php +++ b/app/Http/Controllers/FollowController.php @@ -24,7 +24,7 @@ class FollowController extends Controller 'type' => 'new_follower', 'data' => json_encode([ 'follower_id' => $me->id, - 'follower_username' => $me->username, + 'follower_slug' => $me->slug, 'follower_name' => $me->name, ]), 'created_at' => now(), diff --git a/app/Http/Controllers/GameCommentController.php b/app/Http/Controllers/GameCommentController.php index cda3f17..2e21485 100644 --- a/app/Http/Controllers/GameCommentController.php +++ b/app/Http/Controllers/GameCommentController.php @@ -32,7 +32,7 @@ class GameCommentController extends Controller return response()->json([ 'id' => $comment->id, 'body' => $comment->body, - 'user' => ['name' => $comment->user->name, 'username' => $comment->user->username], + 'user' => ['name' => $comment->user->name, 'slug' => $comment->user->slug], 'user_id' => $comment->user_id, 'created_at' => $comment->created_at->diffForHumans(), 'replies_count' => 0, diff --git a/app/Models/User.php b/app/Models/User.php index 3f10e38..069cad4 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -10,11 +10,11 @@ class User extends Authenticatable { use HasFactory, Notifiable; - protected $fillable = ['name','username','email','password','avatar','bio','location','website','is_private','is_admin']; + protected $fillable = ['name','slug','email','password','avatar','bio','location','website','is_private','is_admin']; protected $hidden = ['password','remember_token']; protected $casts = ['email_verified_at'=>'datetime','password'=>'hashed','is_private'=>'boolean','is_admin'=>'boolean']; - public function getRouteKeyName(): string { return 'username'; } + public function getRouteKeyName(): string { return 'slug'; } public function library(): HasMany { return $this->hasMany(UserGame::class); } public function reviews(): HasMany { return $this->hasMany(Review::class); } diff --git a/database/migrations/2026_05_30_000002_rename_username_to_slug_on_users.php b/database/migrations/2026_05_30_000002_rename_username_to_slug_on_users.php new file mode 100644 index 0000000..09c8aa9 --- /dev/null +++ b/database/migrations/2026_05_30_000002_rename_username_to_slug_on_users.php @@ -0,0 +1,22 @@ +renameColumn('username', 'slug'); + }); + } + + public function down(): void + { + Schema::table('users', function (Blueprint $table) { + $table->renameColumn('slug', 'username'); + }); + } +}; \ No newline at end of file diff --git a/resources/views/activity/index.blade.php b/resources/views/activity/index.blade.php index aabc001..43dec1c 100644 --- a/resources/views/activity/index.blade.php +++ b/resources/views/activity/index.blade.php @@ -40,7 +40,7 @@ @endphp
- - {{ $activity->user?->username ?? 'Unknown' }} + {{ $activity->user?->slug ?? 'Unknown' }} @if($activity->type === 'added_to_library') diff --git a/resources/views/compare/show.blade.php b/resources/views/compare/show.blade.php index a723233..3fe412a 100644 --- a/resources/views/compare/show.blade.php +++ b/resources/views/compare/show.blade.php @@ -1,6 +1,6 @@ @extends('layouts.app') -@section('title', 'Your Library vs ' . ($user->username ?? $user->name) . ' — GameLog') +@section('title', 'Your Library vs ' . ($user->slug ?? $user->name) . ' — GameLog') @section('content')
- @if(!empty($data['follower_username'])) - - {{ $data['follower_name'] ?? $data['follower_username'] }} + {{ $data['follower_name'] ?? $data['follower_slug'] }} @else Someone @@ -40,8 +40,8 @@
{{ $notification->created_at?->diffForHumans() }}
{{ $user->name }}
@endif @if($user->bio) @@ -65,7 +65,7 @@ following: {{ auth()->user()->isFollowing($user) ? 'true' : 'false' }}, async toggle() { const method = this.following ? 'DELETE' : 'POST'; - const res = await fetch('{{ route('users.follow', $user->username) }}', { + const res = await fetch('{{ route('users.follow', $user->slug) }}', { method, headers: { 'X-CSRF-TOKEN': document.querySelector('meta[name=csrf-token]').content, @@ -88,13 +88,13 @@