add methods for EventPicture'
This commit is contained in:
@@ -13,6 +13,7 @@ use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
|
||||
class EventsController extends Controller
|
||||
@@ -136,6 +137,7 @@ class EventsController extends Controller
|
||||
"created_at" => $event->created_at,
|
||||
"updated_at" => $event->updated_at,
|
||||
"tasks" => $event->tasks,
|
||||
"event_photo_path" =>$event->event_photo_path,
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
Log::info($e->getMessage());
|
||||
@@ -164,4 +166,44 @@ class EventsController extends Controller
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function show(int $id)
|
||||
{
|
||||
$event = Event::findOrFail($id);
|
||||
|
||||
return response()->json([
|
||||
'event_photo_path' => $event->event_photo_path
|
||||
]);
|
||||
}
|
||||
|
||||
public function updatePhoto(Request $request, int $id)
|
||||
{
|
||||
$request->validate([
|
||||
'photo' => 'required|image|mimes:jpeg,png,jpg,gif|max:2048',
|
||||
]);
|
||||
$event = Event::findOrFail($id);
|
||||
$path = $request->file('photo')->store('event-photos', 'public');
|
||||
if ($event->event_photo_path) {
|
||||
Storage::disk('public')->delete($event->event_photo_path);
|
||||
}
|
||||
$event->update([
|
||||
'event_photo_path' => $path
|
||||
]);
|
||||
return response()->json([
|
||||
'event_photo_path' => $path
|
||||
]);
|
||||
}
|
||||
public function destroy(int $id)
|
||||
{
|
||||
$event = Event::findOrFail($id);
|
||||
if ($event->event_photo_path) {
|
||||
Storage::disk('public')->delete($event->event_photo_path);
|
||||
$event->update([
|
||||
'event_photo_path' => null
|
||||
]);
|
||||
}
|
||||
return response()->json([
|
||||
'message' => 'Photo supprimée'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class ProfilePhotoController extends Controller
|
||||
{
|
||||
public function show(Request $request)
|
||||
{
|
||||
$user = $request->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']);
|
||||
}
|
||||
}
|
||||
@@ -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