47 lines
1.1 KiB
PHP
47 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Requests\Artworks;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|
|
|
final class ArtworkCreateRequest extends FormRequest
|
|
{
|
|
public function authorize(): bool
|
|
{
|
|
if (! $this->user()) {
|
|
$this->logUnauthorized('missing_user');
|
|
$this->denyAsNotFound();
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'title' => 'required|string|max:150',
|
|
'description' => 'nullable|string',
|
|
'category' => 'nullable|string|max:120',
|
|
'tags' => 'nullable|string|max:200',
|
|
'license' => 'nullable|boolean',
|
|
];
|
|
}
|
|
|
|
private function denyAsNotFound(): void
|
|
{
|
|
throw new NotFoundHttpException();
|
|
}
|
|
|
|
private function logUnauthorized(string $reason): void
|
|
{
|
|
logger()->warning('Artwork create unauthorized access', [
|
|
'reason' => $reason,
|
|
'user_id' => $this->user()?->id,
|
|
'ip' => $this->ip(),
|
|
]);
|
|
}
|
|
}
|