adrema/app/Course/Requests/UpdateRequest.php

49 lines
1.2 KiB
PHP
Raw Normal View History

2021-11-20 00:48:42 +01:00
<?php
namespace App\Course\Requests;
use App\Course\Models\Course;
use App\Course\Models\CourseMember;
use App\Member\Member;
2022-02-19 18:06:07 +01:00
use App\Setting\NamiSettings;
2021-11-20 00:48:42 +01:00
use Illuminate\Foundation\Http\FormRequest;
class UpdateRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, string>
*/
public function rules()
{
return [
'organizer' => 'required|max:255',
'event_name' => 'required|max:255',
'completed_at' => 'required|date',
'course_id' => 'required|exists:courses,id',
];
}
2022-02-19 18:06:07 +01:00
public function persist(Member $member, CourseMember $course, NamiSettings $settings): void
2021-11-20 00:48:42 +01:00
{
2022-02-19 18:06:07 +01:00
$settings->login()->updateCourse(
$member->nami_id,
$course->nami_id,
$this->safe()->merge(['course_id' => Course::find($this->input('course_id'))->nami_id])->toArray()
);
2021-11-20 00:48:42 +01:00
$course->update($this->safe()->toArray());
}
}