2020-04-26 19:09:43 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Requests\API;
|
|
|
|
|
|
|
|
use App\Rules\ImageData;
|
2024-01-10 00:47:09 +00:00
|
|
|
use Illuminate\Support\Str;
|
2020-04-26 19:09:43 +00:00
|
|
|
|
2022-07-29 06:47:10 +00:00
|
|
|
abstract class MediaImageUpdateRequest extends Request
|
2020-04-26 19:09:43 +00:00
|
|
|
{
|
2020-12-22 20:11:22 +00:00
|
|
|
/** @return array<mixed> */
|
2020-04-26 19:09:43 +00:00
|
|
|
public function rules(): array
|
|
|
|
{
|
|
|
|
return [
|
2020-09-06 21:20:42 +00:00
|
|
|
$this->getImageFieldName() => ['string', 'required', new ImageData()],
|
2020-04-26 19:09:43 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2024-01-10 00:47:09 +00:00
|
|
|
public function authorize(): bool
|
2020-04-26 19:09:43 +00:00
|
|
|
{
|
2024-01-10 00:47:09 +00:00
|
|
|
return auth()->user()->is_admin;
|
|
|
|
}
|
2020-04-26 19:09:43 +00:00
|
|
|
|
2024-01-10 00:47:09 +00:00
|
|
|
public function getFileContentAsBinaryString(): string
|
|
|
|
{
|
|
|
|
return base64_decode(Str::after($this->{$this->getImageFieldName()}, ','), true);
|
2020-04-26 19:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getFileExtension(): string
|
|
|
|
{
|
2024-01-10 00:47:09 +00:00
|
|
|
return Str::after(Str::before($this->{$this->getImageFieldName()}, ';'), '/');
|
2020-04-26 19:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
abstract protected function getImageFieldName(): string;
|
|
|
|
}
|