Файловый менеджер - Редактировать - /home/clickysoft/public_html/jmapi5.clickysoft.net/app/Http/Controllers/Api/V1/User/WishlistApiController.php
Назад
<?php namespace App\Http\Controllers\Api\V1\User; use App\Http\Controllers\Controller; use App\Http\Requests\User\StoreWishlistRequest; use App\Http\Resources\User\WishlistResource; use App\Models\Wishlist; use Illuminate\Http\Request; use Symfony\Component\HttpFoundation\Response; use Gate; class WishlistApiController extends Controller { public function index() { $wishlist = Wishlist::where('user_id', auth()->id())->get(); WishlistResource::withoutWrapping(); return WishlistResource::collection($wishlist); } public function store(StoreWishlistRequest $request) { $wishlist = Wishlist::create(array_merge($request->all(), ['user_id' => auth()->id()])); return (new WishlistResource($wishlist)) ->response() ->setStatusCode(Response::HTTP_CREATED); } public function show(Wishlist $wishlist) { abort_if(Gate::denies('update-record', $wishlist), Response::HTTP_FORBIDDEN, '403 Forbidden'); return new WishlistResource($wishlist); } public function update(StoreWishlistRequest $request, Wishlist $wishlist) { abort_if(Gate::denies('update-record', $wishlist), Response::HTTP_FORBIDDEN, '403 Forbidden'); $wishlist->update($request->all()); return (new WishlistResource($wishlist)) ->response() ->setStatusCode(Response::HTTP_CREATED); } public function destroy(Wishlist $wishlist) { abort_if(Gate::denies('update-record', $wishlist), Response::HTTP_FORBIDDEN, '403 Forbidden'); try { $wishlist->delete(); return response() ->json(['message' => 'Wishlist item deleted successfully'], Response::HTTP_OK); }catch (\Exception $e){ \Log::channel('db_errors')->info('Record Deletion Error : Wishlist Item -> '.$wishlist->id); \Log::channel('db_errors')->info($e->getMessage()); return response() ->json([ 'message' => "Record not deleted.", 'errors' => ["error" => ["Unable to delete wishlist item."]] ], Response::HTTP_INTERNAL_SERVER_ERROR); } } public function clearBulkWishlist(Request $request) { $request->validate([ 'ids' => 'required|array', 'ids.*' => 'exists:wishlists,id,user_id,'.auth()->id(), ],[ 'ids.*.exists' => 'Id #:position is invalid.', ]); try { Wishlist::whereIn('id', $request->get('ids'))->delete(); return response() ->json(['message' => 'Wishlist items deleted successfully'], Response::HTTP_OK); }catch (\Exception $e){ \Log::channel('db_errors')->info('Record Deletion Error : Wishlist items'); \Log::channel('db_errors')->info($e->getMessage()); return response() ->json([ 'message' => "Record not deleted.", 'errors' => ["error" => ["Unable to delete wishlist items."]] ], Response::HTTP_INTERNAL_SERVER_ERROR); } } public function clearWishlist() { try { $items = Wishlist::where('user_id', auth()->id()); if($items->count() == 0){ return response() ->json([ 'message' => "Empty wishlist.", 'errors' => ["error" => ["Nothing to delete. Wishlist already empty."]] ], Response::HTTP_NOT_FOUND); }else{ $items->delete(); return response() ->json(['message' => 'Wishlist deleted successfully'], Response::HTTP_OK); } }catch (\Exception $e){ \Log::channel('db_errors')->info('Record Deletion Error : Wishlist'); \Log::channel('db_errors')->info($e->getMessage()); return response() ->json([ 'message' => "Record not deleted.", 'errors' => ["error" => ["Unable to delete wishlist."]] ], Response::HTTP_INTERNAL_SERVER_ERROR); } } }
| ver. 1.4 |
Github
|
.
| PHP 8.1.29 | Генерация страницы: 0 |
proxy
|
phpinfo
|
Настройка