42 lines
965 B
PHP
42 lines
965 B
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use Illuminate\Contracts\Validation\ValidationRule;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
class StoreReviewRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
$review = $this->route('review');
|
|
if( $review )
|
|
return $this->user()->can('update', $review);
|
|
|
|
return $this->user()->can('create', '\App\Models\EntryReview');
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array<string, ValidationRule|array<mixed>|string>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
|
|
$isEdit = (bool) $this->route('review');
|
|
|
|
$rules = [];
|
|
|
|
$rules['rating'] = 'required|numeric|min:1|max:5';
|
|
$rules['title'] = 'required|string|max:255';
|
|
$rules['description'] = 'required|string';
|
|
|
|
return $rules;
|
|
|
|
}
|
|
}
|