Repository URL to install this package:
|
Version:
0.2.1 ▾
|
<?php
namespace Modules\Students\Http\Requests;
use Modules\Core\Http\Requests\Request;
class EditStudentRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;//policy(CoursesController::class)->create(Auth::user());
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
$rules = [
'first_name' => 'required|max:100',
'middle_name' => 'required|max:100',
'last_name' => 'required|max:100',
'profile_photo' => 'image',
'birthday' => 'required|date|before:17 years ago',
'country' => 'required|in:'.implode(',', array_keys(\Location::lists())),
'professional_doc' => 'required',
'phone' => 'required|phone:AUTO,MX',
'email' => 'required|email',
'password' => 'confirmed|string|min:6',
'is_active' => 'boolean',
];
if(\Module::has('Users')){
$rules['email'] .= '|unique:users,email,'.$this->route('students').',student_id';
}
return $rules;
}
/**
* Sanitize input before validation.
*
* @return array
*/
public function sanitize()
{
$input = array_map('trim', $this->all());
if(!isset($input['is_active'])) {
$input['is_active'] = false;
}
if(isset($input['birthday'])) {
$input['birthday'] = \Carbon\Carbon::createFromFormat(trans('core::core.formats.date.php'), $input['birthday'])->toDateString();
}
$this->replace($input);
return $this->all();
}
public function response(array $errors)
{
$input = array_map('trim', $this->all());
if(isset($input['birthday'])) {
$input['birthday'] = (string) \Carbon\Carbon::parse($input['birthday'])->format(trans('core::core.formats.date.php'));
}
$this->replace($input);
return parent::response($errors);
}
}