validOrFail($restaurante_id); $restaurante = Restaurante::findOrFail($restaurante_id); $canalesVenta = $restaurante->canalesVenta(); $paginate = app(PaginatorService::class)->paginate( perPage: $request->input('per_page', 15), page: $request->input('page', 1), total: $canalesVenta->count(), route: 'canales-venta.all', data: [$restaurante_id], ); return response()->json([ 'pagination' => $paginate, 'data' => array_values($canalesVenta->get()->skip($paginate['from'] - 1)->take($paginate['per_page'])->all()) ]); } /** * Obtiene un canal de venta por su id * @param $restaurante_id * @param $id * @return JsonResponse */ public function get($restaurante_id, $id) { app(UuidService::class)->validOrFail($id); app(UuidService::class)->validOrFail($restaurante_id); $restaurante = Restaurante::findOrFail($restaurante_id); $canalVenta = CanalVenta::findOrFail($id); return response()->json($canalVenta); } ///** // * Crea un nuevo restaurant // * @param Request $request // * @return JsonResponse // * @throws ValidationException // */ //public function create(Request $request) { // $this->validate($request, [ // 'nombre' => 'required' // ]); // if (!$request->user->canManageRestaurants()) { // return response()->json([ // 'error' => 'cant_manage_restaurants', // 'message' => 'El usuario ' . $request->user->id . ' no tiene permisos para manipular restaurantes' // ], 403); // } // $restaurant = Restaurante::create([ // 'id' => Uuid::uuid4(), // 'nombre' => $request->input('nombre') // ]); // return response()->json($restaurant, 201); //} ///** // * Actualiza un restaurante // * @param Request $request // * @param $id // * @return JsonResponse // * @throws ValidationException // */ //public function update(Request $request, $id) { // $this->validate($request, [ // 'nombre' => 'required' // ]); // if (!$request->user->canManageRestaurants()) { // return response()->json([ // 'error' => 'cant_manage_restaurants', // 'message' => 'El usuario ' . $request->user->id . ' no tiene permisos para manipular restaurantes' // ], 403); // } // $restaurant = Restaurante::findOrNull($id); // if(!$restaurant) { // return response()->json([ // 'error' => 'not_found', // 'message' => 'El restaurante con id ' . $id . ' no existe' // ], 404); // } // $restaurant->nombre = $request->input('nombre'); // $restaurant->save(); // return response()->json($restaurant); //} ///** // * Elimina un restaurante // * @param Request $request // * @param $id // * @return JsonResponse // * @throws ValidationException // */ //public function delete(Request $request, $id) { // if (!$request->user->canManageRestaurants()) { // return response()->json([ // 'error' => 'cant_manage_restaurants', // 'message' => 'El usuario ' . $request->user->id . ' no tiene permisos para manipular restaurantes' // ], 403); // } // $restaurant = Restaurante::findOrNull($id); // if(!$restaurant) { // return response()->json([ // 'error' => 'not_found', // 'message' => 'El restaurante con id ' . $id . ' no existe' // ], 404); // } // $restaurant->delete(); // return response()->json($restaurant); //} }