mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-07 05:31:24 +00:00
* Convert string references to `::class` PHP 5.5.9 adds the new static `class` property which provides the fully qualified class name. This is preferred over using strings for class names since the `class` property references are checked by PHP. * Use Faker methods Accessing Faker properties was deprecated in Faker 1.14. * Convert route options to fluent methods Laravel 8 adopts the tuple syntax for controller actions. Since the old options array is incompatible with this syntax, Shift converted them to use modern, fluent methods. * Adopt class based routes * Remove default `app` files * Shift core files * Streamline config files * Set new `ENV` variables * Default new `bootstrap/app.php` * Re-register HTTP middleware * Consolidate service providers * Re-register service providers * Re-register routes * Re-register scheduled commands * Bump Composer dependencies * Use `<env>` tags for configuration `<env>` tags have a lower precedence than system environment variables making it easier to overwrite PHPUnit configuration values in additional environments, such a CI. Review this blog post for more details on configuration precedence when testing Laravel: https://jasonmccreary.me/articles/laravel-testing-configuration-precedence/ * Adopt anonymous migrations * Rename `password_resets` table * Convert `$casts` property to method * Adopt Laravel type hints * Mark base controller as `abstract` * Remove `CreatesApplication` testing trait * Shift cleanup * Fix shift first issues * Updating Rules for laravel 11, sanctum config and pint * Fix Carbon issue on dashboard * Temporary fix for tests while migration is issue fixed on laravel side * Carbon needs numerical values, not strings * Minimum php version * Fix domain installation step not fetching the correct company_id * Fix Role Policy wasn't properly registered ---------
124 lines
3.3 KiB
PHP
124 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\V1\Admin\Settings;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\AvatarRequest;
|
|
use App\Http\Requests\CompanyLogoRequest;
|
|
use App\Http\Requests\CompanyRequest;
|
|
use App\Http\Requests\ProfileRequest;
|
|
use App\Http\Resources\CompanyResource;
|
|
use App\Http\Resources\UserResource;
|
|
use App\Models\Company;
|
|
use Illuminate\Http\Request;
|
|
|
|
class CompanyController extends Controller
|
|
{
|
|
/**
|
|
* Retrive the Admin account.
|
|
*
|
|
* @return \Illuminate\Http\JsonResponse
|
|
*/
|
|
public function getUser(Request $request)
|
|
{
|
|
return new UserResource($request->user());
|
|
}
|
|
|
|
/**
|
|
* Update the Admin profile.
|
|
* Includes name, email and (or) password
|
|
*
|
|
* @return \Illuminate\Http\JsonResponse
|
|
*/
|
|
public function updateProfile(ProfileRequest $request)
|
|
{
|
|
$user = $request->user();
|
|
|
|
$user->update($request->validated());
|
|
|
|
return new UserResource($user);
|
|
}
|
|
|
|
/**
|
|
* Update Admin Company Details
|
|
*
|
|
* @return \Illuminate\Http\JsonResponse
|
|
*/
|
|
public function updateCompany(CompanyRequest $request)
|
|
{
|
|
$company = Company::find($request->header('company'));
|
|
|
|
$this->authorize('manage company', $company);
|
|
|
|
$company->update($request->getCompanyPayload());
|
|
|
|
$company->address()->updateOrCreate(['company_id' => $company->id], $request->address);
|
|
|
|
return new CompanyResource($company);
|
|
}
|
|
|
|
/**
|
|
* Upload the company logo to storage.
|
|
*
|
|
* @return \Illuminate\Http\JsonResponse
|
|
*/
|
|
public function uploadCompanyLogo(CompanyLogoRequest $request)
|
|
{
|
|
$company = Company::find($request->header('company'));
|
|
|
|
$this->authorize('manage company', $company);
|
|
|
|
$data = json_decode($request->company_logo);
|
|
|
|
if (isset($request->is_company_logo_removed) && (bool) $request->is_company_logo_removed) {
|
|
$company->clearMediaCollection('logo');
|
|
}
|
|
if ($data) {
|
|
$company = Company::find($request->header('company'));
|
|
|
|
if ($company) {
|
|
$company->clearMediaCollection('logo');
|
|
|
|
$company->addMediaFromBase64($data->data)
|
|
->usingFileName($data->name)
|
|
->toMediaCollection('logo');
|
|
}
|
|
}
|
|
|
|
return response()->json([
|
|
'success' => true,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Upload the Admin Avatar to public storage.
|
|
*
|
|
* @return \Illuminate\Http\JsonResponse
|
|
*/
|
|
public function uploadAvatar(AvatarRequest $request)
|
|
{
|
|
$user = auth()->user();
|
|
|
|
if (isset($request->is_admin_avatar_removed) && (bool) $request->is_admin_avatar_removed) {
|
|
$user->clearMediaCollection('admin_avatar');
|
|
}
|
|
if ($user && $request->hasFile('admin_avatar')) {
|
|
$user->clearMediaCollection('admin_avatar');
|
|
|
|
$user->addMediaFromRequest('admin_avatar')
|
|
->toMediaCollection('admin_avatar');
|
|
}
|
|
|
|
if ($user && $request->has('avatar')) {
|
|
$data = json_decode($request->avatar);
|
|
$user->clearMediaCollection('admin_avatar');
|
|
|
|
$user->addMediaFromBase64($data->data)
|
|
->usingFileName($data->name)
|
|
->toMediaCollection('admin_avatar');
|
|
}
|
|
|
|
return new UserResource($user);
|
|
}
|
|
}
|