<?php
namespace QxCMS\Modules\Client\Requests\Officers;
use Illuminate\Foundation\Http\FormRequest;
class OfficerRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
$client = auth('client')->user()->client;
$dateformat = $client->date_picker;
if($this->getId()) {
return [
'name' => 'required',
'access_type' => 'required',
'email' => 'required|email|unique:qxcms.client_users,email,'.(($this->getId()) ? $this->getId():'NULL').',id,client_id,'.auth()->user()->client->id,
'username' => 'required|unique:qxcms.client_users,username,'.(($this->getId()) ? $this->getId():'NULL').',id,client_id,'.auth()->user()->client->id,
'status' => 'required',
'password' => 'min:6',
'password_confirmation' => 'required_with:password|same:password',
'validity_date' => 'date_format:'.$dateformat['php'],
];
}
return [
'name' => 'required',
'access_type' => 'required',
'email' => 'required|email|unique:qxcms.client_users,email,'.(($this->getId()) ? $this->getId():'NULL').',id,client_id,'.auth()->user()->client->id,
'username' => 'required|unique:qxcms.client_users,username,'.(($this->getId()) ? $this->getId():'NULL').',id,client_id,'.auth()->user()->client->id,
'status' => 'required',
'password' => 'required|min:6',
'password_confirmation' => 'required|same:password',
'validity_date' => 'date_format:'.$dateformat['php'],
];
}
public function messages()
{
return [
'password_confirmation.required' => 'The re-type password field is required.',
'password_confirmation.required_with' => 'The re-type password field is required when changing password.',
'password_confirmation.same' => 'The re-type password and password must match.',
//'validity_date.required' => 'The account period validity field is required.',
'validity_date.date_format' => 'The account period validity date does not match the format :format.'
];
}
public function getId()
{
return decode($this->officer);
}
}