organization_id !== $organization->getKey()) { throw new AuthorizationException('Tag does not belong to organization'); } } /** * Get clients * * @return ClientCollection * * @throws AuthorizationException * * @operationId getClients */ public function index(Organization $organization): ClientCollection { $this->checkPermission($organization, 'clients:view'); $clients = Client::query() ->whereBelongsTo($organization, 'organization') ->orderBy('created_at', 'desc') ->paginate(); return new ClientCollection($clients); } /** * Create client * * @throws AuthorizationException * * @operationId createClient */ public function store(Organization $organization, TagStoreRequest $request): ClientResource { $this->checkPermission($organization, 'clients:create'); $client = new Client(); $client->name = $request->input('name'); $client->organization()->associate($organization); $client->save(); return new ClientResource($client); } /** * Update client * * @throws AuthorizationException * * @operationId updateClient */ public function update(Organization $organization, Client $client, TagUpdateRequest $request): ClientResource { $this->checkPermission($organization, 'clients:update', $client); $client->name = $request->input('name'); $client->save(); return new ClientResource($client); } /** * Delete client * * @throws AuthorizationException * * @operationId deleteClient */ public function destroy(Organization $organization, Client $client): JsonResponse { $this->checkPermission($organization, 'clients:delete', $client); $client->delete(); return response()->json(null, 204); } }