EscolaLMS/Courses

View on GitHub
src/Http/Requests/ListCourseAPIRequest.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 ListCourseAPIRequest extends FormRequest
{
    public function authorize(): bool
    {
        $user = auth()->user();
        return isset($user) ? $user->can('list', Course::class) : true;
    }

    public function rules(): array
    {
        return [
            'categories' => ['array', 'prohibited_unless:category_id,null'],
            'categories.*' => ['integer'],
            'category_id' => ['integer'],
            'group_id' => ['integer'],
            'no_expired' => ['boolean'],
            'order_by' => ['string', 'in:id,title,created_at,status'],
        ];
    }
}