authorize('view', $website); return view('funnels.index', [ 'website' => $website, 'funnels' => $website->funnels()->orderBy('name')->get(), ]); } public function create(Website $website): View { $this->authorize('view', $website); return view('funnels.create', [ 'website' => $website, ]); } public function store(Request $request, Website $website): RedirectResponse { $this->authorize('view', $website); $validated = $request->validate([ 'name' => 'required|string|max:255', 'steps' => 'required|array|min:2', 'steps.*.type' => 'required|in:pageview,event', 'steps.*.value' => 'required|string|max:255', 'steps.*.label' => 'required|string|max:255', ]); $website->funnels()->create($validated); return redirect() ->route('funnels.index', $website) ->with('success', 'Funnel created successfully.'); } public function show(Request $request, Website $website, Funnel $funnel): View { $this->authorize('view', $website); [$from, $to] = $this->parseDateRange($request); $service = new FunnelAnalysisService($funnel, $from, $to); return view('funnels.show', [ 'website' => $website, 'funnel' => $funnel, 'steps' => $service->analyze(), 'from' => $from, 'to' => $to, ]); } public function edit(Website $website, Funnel $funnel): View { $this->authorize('view', $website); return view('funnels.edit', [ 'website' => $website, 'funnel' => $funnel, ]); } public function update(Request $request, Website $website, Funnel $funnel): RedirectResponse { $this->authorize('view', $website); $validated = $request->validate([ 'name' => 'required|string|max:255', 'steps' => 'required|array|min:2', 'steps.*.type' => 'required|in:pageview,event', 'steps.*.value' => 'required|string|max:255', 'steps.*.label' => 'required|string|max:255', ]); $funnel->update($validated); return redirect() ->route('funnels.show', [$website, $funnel]) ->with('success', 'Funnel updated successfully.'); } public function destroy(Website $website, Funnel $funnel): RedirectResponse { $this->authorize('view', $website); $funnel->delete(); return redirect() ->route('funnels.index', $website) ->with('success', 'Funnel deleted.'); } }