57 lines
1.7 KiB
PHP
57 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
class ReportRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
return Auth::check() && is_role(['3']);
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
$rules = [
|
|
'title' => ['required'],
|
|
'publication_date' => ['required', 'date'],
|
|
'link' => ['required', 'url'],
|
|
'description' => ['nullable'],
|
|
];
|
|
|
|
if($this->isMethod('post')){
|
|
$rules['proof'] = ['required', 'image', 'mimes:png,jpg,jpeg', 'max:2048'];
|
|
}else{
|
|
$rules['proof'] = ['nullable', 'image', 'mimes:png,jpg,jpeg', 'max:2048'];
|
|
}
|
|
|
|
return $rules;
|
|
}
|
|
|
|
public function messages(): array
|
|
{
|
|
return [
|
|
'title.required' => 'Judul wajib diisi.',
|
|
'publication_date.required' => 'Tanggal publikasi wajib diisi.',
|
|
'publication_date.date' => 'Tanggal publikasi harus berupa format tanggal yang valid.',
|
|
'link.required' => 'Link wajib diisi.',
|
|
'link.url' => 'Format link tidak valid.',
|
|
'proof.required' => 'Bukti tayang wajib diunggah.',
|
|
'proof.image' => 'Bukti tayang harus berupa gambar.',
|
|
'proof.mimes' => 'Format gambar harus PNG, JPG, atau JPEG.',
|
|
'proof.max' => 'Ukuran gambar tidak boleh lebih dari 2MB.',
|
|
];
|
|
}
|
|
|
|
}
|