39 lines
996 B
PHP
39 lines
996 B
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Campaign;
|
|
|
|
use App\Enums\UserRoles;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class StoreNotifCampaign extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*
|
|
* @return bool
|
|
*/
|
|
public function authorize()
|
|
{
|
|
return Auth::check() && (Auth::user()->roles === UserRoles::superadmin()->value || Auth::user()->roles === UserRoles::admin()->value);
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function rules()
|
|
{
|
|
return [
|
|
'notif_name' => 'min:5|required',
|
|
'notif_email' => [
|
|
'required',
|
|
Rule::unique('notification')->where(function ($query) {
|
|
return $query->where('notif_campId', $this->campaign->camp_id);
|
|
}),
|
|
]
|
|
];
|
|
}
|
|
}
|