json(Channel::query()->orderBy('name')->paginate($this->limit())); } public function show(Channel $channel) { return response()->json($channel); } public function store(Request $request) { $channel = Channel::create($this->attributes($request)); return response() ->json($channel, 201) ->header('Location', route('api.ecommerce-finance.channels.show', $channel)); } public function update(Channel $channel, Request $request) { $channel->update($request->validated()); return response()->json($channel->fresh()); } private function attributes(Request $request): array { return array_merge($request->validated(), [ 'company_id' => company_id(), 'created_by' => user_id(), 'created_from' => 'ecommerce-finance', ]); } private function limit(): int { return min(max((int) request('limit', 25), 1), 100); } }