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'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user