add methods for EventPicture'
This commit is contained in:
@@ -25,6 +25,7 @@ use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use App\Services\UserService;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Pest\Support\Str;
|
||||
use Propaganistas\LaravelPhone\PhoneNumber;
|
||||
|
||||
@@ -454,4 +455,41 @@ class UserController extends Controller
|
||||
return response()->json(['message' => 'Server error'], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function show(Request $request)
|
||||
{
|
||||
$user = $request->user();
|
||||
return response()->json(['profile_photo_path' => $user->profile_photo_path]);
|
||||
}
|
||||
|
||||
public function updatePhoto(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']);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user