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' => $restaurante_id], ); $data = $canalesVenta->get() ->skip($paginate['from'] - 1) ->take($paginate['per_page']) ->all(); return response()->json([ 'pagination' => $paginate, 'data' => $data ]); } /** * Obtiene un canal de venta por su id */ 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 canal de venta * @param Request $request * @return JsonResponse * @throws ValidationException */ public function create(Request $request) { $this->validate($request, [ 'nombre' => 'required', 'sector_id' => 'required|exists:sectores,id', 'restaurante_id' => 'required|exists:restaurantes,id', 'tipo_canal_id' => 'required|exists:tipos_canal,id' ]); $restaurant = Restaurante::create([ 'id' => Uuid::uuid4(), 'nombre' => $request->input('nombre') ]); return response()->json($restaurant, 201); } }