companyFromHeader($request); $this->authorize('manage company', $company); $company->update($request->getCompanyPayload()); $address = (array) $request->input('address'); $this->companyAddressWriter->upsert($company, $address); return new CompanyResource($company); } /** * Replace or drop the company logo. * * Two independent switches, in this order: the removal flag wipes whatever * is on file, and a submitted image is then stored — so a payload carrying * both ends up with the new image. The image arrives as a JSON envelope * holding a file name and a data URI, already checked by the form request, * and an envelope that decodes to nothing is simply ignored. */ public function uploadCompanyLogo(CompanyLogoRequest $request) { $company = $this->companyFromHeader($request); $this->authorize('manage company', $company); if ($this->removalRequested($request)) { $this->companyLogoManager->clear($company); } $envelope = json_decode((string) $request->input('company_logo')); if ($envelope) { $this->companyLogoManager->replaceBase64($company, $envelope->data, $envelope->name); } return response()->json([ 'success' => true, ]); } /** * The company named by the request header, or null when the header names * nothing on file — the gate is then asked about a company that is not * there, exactly as before. */ private function companyFromHeader(Request $request): ?Company { return Company::query()->find($request->header('company')); } /** * Whether the caller asked for the current logo to be dropped. * * Present-and-not-null, then cast to a boolean: `"0"` and the empty string * read as no, but the string `"false"` reads as yes. Kept as it stands. */ private function removalRequested(Request $request): bool { $flag = $request->input('is_company_logo_removed'); return $flag !== null && (bool) $flag; } }