mirror of
https://github.com/HolgerHatGarKeineNode/einundzwanzig-app.git
synced 2026-06-17 16:40:31 +00:00
1518611bdb
- ✨ Added `StoreCourseRequest` and `UpdateCourseRequest` for structured validation. - ✨ Introduced `StoreCourseEventRequest` and `UpdateCourseEventRequest` for consistent request validation. - 🖼️ Created `CourseResource` and `CourseEventResource` for API responses. - 🔄 Refactored `CourseController` and `CourseEventController` to use Policies and FormRequests. - ✨ Added dedicated `uploadLogo` and `uploadAvatar` API endpoints with shared media validation. - 🚀 Improved API by aligning Course and CourseEvent behavior with other entities.
47 lines
1.0 KiB
PHP
47 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Api;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
class UploadMediaRequest extends FormRequest
|
|
{
|
|
public function authorize(): bool
|
|
{
|
|
$model = $this->boundModel();
|
|
|
|
return $model !== null && $this->user()->can('update', $model);
|
|
}
|
|
|
|
/**
|
|
* @return array<string, array<int, string>>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'file' => [
|
|
'required',
|
|
'image',
|
|
'mimes:jpeg,png,webp,avif',
|
|
'max:5120',
|
|
'dimensions:max_width=4000,max_height=4000',
|
|
],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* The route-bound model whose media is being replaced (meetup, lecturer, course).
|
|
*/
|
|
protected function boundModel(): ?Model
|
|
{
|
|
foreach ($this->route()->parameters() as $parameter) {
|
|
if ($parameter instanceof Model) {
|
|
return $parameter;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|