EscolaLMS/Courses

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

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
<?php

namespace EscolaLms\Courses\Http\Requests;

use EscolaLms\Courses\Models\Course;
use Illuminate\Foundation\Http\FormRequest;

class DeleteCourseAPIRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        $user = auth()->user();
        $course = $this->getCourse();
        return is_null($course) || (isset($user) ? $user->can('delete', $course) : false);
    }

    public function getCourse(): ?Course
    {
        return Course::find($this->route('course'));
    }

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