Файловый менеджер - Редактировать - /home/clickysoft/public_html/benchexc.clickysoft.net/app/Repositories/Api/CompanyApiRepository.php
Назад
<?php namespace App\Repositories\Api; use App\Http\Resources\CompanyResource; use App\Interfaces\Api\CompanyApiRepositoryInterface; use App\Models\Company; use App\Models\CompanyIndustry; use Illuminate\Support\Facades\Storage; class CompanyApiRepository implements CompanyApiRepositoryInterface { public function getCompanyProfile($companyId = null){ $company = $companyId ? Company::find($companyId) : auth()->user()->companyDetail; if(empty($company)){ return makeJsonResponse(false, 'error', 422, [], [['Company not found.']]); } return makeJsonResponse(true, 'success', 200, new CompanyResource($company)); } public function updateCompanyProfile($request){ $company = auth()->user()->companyDetail; if (!$company) { return makeJsonResponse(false, 'error', 422, [], [['Company not found.']]); } if($request->hasAny(['company_name', 'industry_id', 'contact_person_name', 'phone_number', 'location'])) { $company->update($request->all()); CompanyIndustry::where('company_id', $company->id)->delete(); foreach ($request->industry_id as $industry){ CompanyIndustry::create([ 'user_id' => $company->user_id, 'company_id' => $company->id, 'industry_id' => $industry ]); } }else{ $company->update($request->all()); } return makeJsonResponse(true, 'success', 200, new CompanyResource($company)); } public function updateCompanyLogo($request) { $company = auth()->user()->companyDetail; if(empty($company)){ return makeJsonResponse(false, 'error', 422, [], [['Company not found.']]); } $image = $request->file('logo'); // Create a unique filename with the company ID and original extension $filename = pathinfo($image->getClientOriginalName(), PATHINFO_FILENAME); $extension = $image->getClientOriginalExtension(); $filename = "{$filename}-{$company->id}.{$extension}"; // Define storage directory path $dirPath = "company-logo/{$company->id}"; // Delete the old logo if it exists if ($company->logo && Storage::exists("public/{$dirPath}/{$company->logo}")) { Storage::delete("public/{$dirPath}/{$company->logo}"); } // Ensure the directory exists, then store the new image Storage::makeDirectory($dirPath); $image->storeAs("public/{$dirPath}", $filename); // Update the company logo path and save $company->logo = $filename; $company->save(); $newImageUrl = asset("storage/{$dirPath}/{$filename}"); return makeJsonResponse(true, 'success', 200, [ 'logo' => $newImageUrl ]); } }
| ver. 1.4 |
Github
|
.
| PHP 8.1.29 | Генерация страницы: 0 |
proxy
|
phpinfo
|
Настройка