From ffa77ad38699888e5416e5a7b4a074413c232795 Mon Sep 17 00:00:00 2001 From: p2405951 Date: Tue, 24 Feb 2026 16:43:16 +0100 Subject: [PATCH] recup stash --- .../Controllers/ProfilePhotoController.php | 47 +++++++++++++++++++ ..._add_profile_photo_path_to_users_table.php | 28 +++++++++++ routes/api.php | 8 ++++ 3 files changed, 83 insertions(+) create mode 100644 app/Http/Controllers/ProfilePhotoController.php create mode 100644 database/migrations/2026_02_24_133410_add_profile_photo_path_to_users_table.php diff --git a/app/Http/Controllers/ProfilePhotoController.php b/app/Http/Controllers/ProfilePhotoController.php new file mode 100644 index 0000000..9f40480 --- /dev/null +++ b/app/Http/Controllers/ProfilePhotoController.php @@ -0,0 +1,47 @@ +user(); + return response()->json(['profile_photo_path' => $user->profile_photo_path]); + } + + public function update(Request $request) + { + $request->validate([ + 'photo' => 'required|image|mimes:jpeg,png,jpg,gif|max:2048', + ]); + + $user = $request->user(); + $path = $request->file('photo')->store('profile-photos', 'public'); + + // Supprimer l'ancienne photo si elle existe + if ($user->profile_photo_path) { + Storage::disk('public')->delete($user->profile_photo_path); + } + + $user->update(['profile_photo_path' => $path]); + + return response()->json(['profile_photo_path' => $path]); + } + + public function destroy(Request $request) + { + $user = $request->user(); + + if ($user->profile_photo_path) { + Storage::disk('public')->delete($user->profile_photo_path); + $user->update(['profile_photo_path' => null]); + } + + return response()->json(['message' => 'Photo supprimée']); + } +} diff --git a/database/migrations/2026_02_24_133410_add_profile_photo_path_to_users_table.php b/database/migrations/2026_02_24_133410_add_profile_photo_path_to_users_table.php new file mode 100644 index 0000000..ffcd140 --- /dev/null +++ b/database/migrations/2026_02_24_133410_add_profile_photo_path_to_users_table.php @@ -0,0 +1,28 @@ +string('profile_photo_path', 2048)->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('users', function (Blueprint $table) { + $table->dropColumn('profile_photo_path'); + }); + } +}; diff --git a/routes/api.php b/routes/api.php index 704c8b3..079039c 100644 --- a/routes/api.php +++ b/routes/api.php @@ -3,6 +3,14 @@ use Illuminate\Http\Request; use Illuminate\Support\Facades\Route; use App\Http\Controllers\ExportController; +use App\Http\Controllers\ProfilePhotoController; + +Route::middleware('auth:sanctum')->group(function () { + Route::post('/profile-photo', [ProfilePhotoController::class, 'update']); + Route::delete('/profile-photo', [ProfilePhotoController::class, 'destroy']); + Route::get('/profile-photo', [ProfilePhotoController::class, 'show']); +}); + Route::get('/export/ics/{userId}', [ExportController::class, 'exportIcs']); Route::get("/hello", function (Request $request) {