EscolaLMS/Courses

View on GitHub
src/Http/Requests/DeleteLessonAPIRequest.php

Summary

Maintainability
A
1 hr
Test Coverage
A
100%
<?php

namespace EscolaLms\Courses\Http\Requests;

use EscolaLms\Courses\Models\Lesson;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class DeleteLessonAPIRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        $user = auth()->user();
        $lesson = $this->getLesson();
        return is_null($lesson) || (isset($user) && $user->can('delete', $lesson));
    }

    public function getLesson(): ?Lesson
    {
        return Lesson::find($this->route('lesson'));
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [];
    }
}