feat: rename avatarUri column

This commit is contained in:
Leon 2026-01-05 09:50:51 +01:00
parent 9e6680c1c0
commit 7a71652bf1
5 changed files with 36 additions and 8 deletions

View File

@ -17,19 +17,19 @@ public function register(RegisterRequest $request): JsonResponse
{ {
$data = $request->validated(); $data = $request->validated();
$avatarUri = null; $avatar_uri = null;
if ($request->hasFile('avatar')) { if ($request->hasFile('avatar')) {
$filename = \Illuminate\Support\Str::uuid() . '.jpg'; $filename = \Illuminate\Support\Str::uuid() . '.jpg';
$path = $request->file('avatar')->storeAs('avatars', $filename, 'public'); $path = $request->file('avatar')->storeAs('avatars', $filename, 'public');
$avatarUri = url('storage/' . $path); $avatar_uri = url('storage/' . $path);
} }
$user = User::create([ $user = User::create([
'username' => $data['username'], 'username' => $data['username'],
'email' => $data['email'], 'email' => $data['email'],
'password' => $data['password'], 'password' => $data['password'],
'avatarUri' => $avatarUri, 'avatar_uri' => $avatar_uri,
]); ]);
$token = $user->createToken( $token = $user->createToken(

View File

@ -13,7 +13,7 @@ class HuntsController extends Controller
public function index() public function index()
{ {
try { try {
$hunts = Hunts::with('participants:id,avatarUri')->paginate(10); $hunts = Hunts::with('participants:id,avatar_uri')->paginate(10);
return response()->json($hunts); return response()->json($hunts);
} catch (\Exception $e) { } catch (\Exception $e) {
\Illuminate\Support\Facades\Log::error('Error fetching hunts: ' . $e->getMessage()); \Illuminate\Support\Facades\Log::error('Error fetching hunts: ' . $e->getMessage());
@ -47,7 +47,7 @@ class HuntsController extends Controller
*/ */
public function show(Request $request, $id) public function show(Request $request, $id)
{ {
$hunt = Hunts::with(['steps', 'participants:id,avatarUri'])->find($id); $hunt = Hunts::with(['steps', 'participants:id,avatar_uri'])->find($id);
if (!$hunt) { if (!$hunt) {
return response()->json(['message' => 'Hunt not found'], 404); return response()->json(['message' => 'Hunt not found'], 404);

View File

@ -31,12 +31,12 @@ class UsersController extends Controller
$path = $request->file('avatar')->storeAs('avatars', $filename, 'public'); $path = $request->file('avatar')->storeAs('avatars', $filename, 'public');
$user->update([ $user->update([
'avatarUri' => url('storage/' . $path), 'avatar_uri' => url('storage/' . $path),
]); ]);
return response()->json([ return response()->json([
'message' => 'Avatar updated successfully', 'message' => 'Avatar updated successfully',
'avatarUri' => $user->avatarUri, 'avatar_uri' => $user->avatar_uri,
]); ]);
} }
} }

View File

@ -27,7 +27,7 @@ class User extends Authenticatable
'password', 'password',
'role', 'role',
'xp', 'xp',
'avatarUri', 'avatar_uri',
'participations', 'participations',
'victories' 'victories'
]; ];

View File

@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('users', function (Blueprint $table) {
$table->renameColumn('avatarUri', 'avatar_uri');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('users', function (Blueprint $table) {
$table->renameColumn('avatar_uri', 'avatarUri');
});
}
};