56 lines
1.5 KiB
PHP
Raw Normal View History

2017-09-14 22:21:00 +03:00
<?php
namespace App\Http\Requests\Auth;
use Illuminate\Foundation\Http\FormRequest;
class User 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()
{
2019-11-16 10:21:14 +03:00
$picture = 'nullable';
if ($this->request->get('picture', null)) {
$picture = 'mimes:' . config('filesystems.mimes') . '|between:0,' . config('filesystems.max_size') * 1024;
}
2017-09-14 22:21:00 +03:00
if ($this->getMethod() == 'PATCH') {
2020-10-05 11:11:59 +03:00
// Updating user
2019-11-16 10:21:14 +03:00
$id = is_numeric($this->user) ? $this->user : $this->user->getAttribute('id');
2020-10-05 11:11:59 +03:00
$password = '';
$companies = $this->user->can('read-common-companies') ? 'required' : '';
$roles = $this->user->can('read-auth-roles') ? 'required' : '';
2017-09-14 22:21:00 +03:00
} else {
2020-10-05 11:11:59 +03:00
// Creating user
2017-09-14 22:21:00 +03:00
$id = null;
2020-10-05 11:11:59 +03:00
$password = 'required|';
$companies = 'required';
$roles = 'required';
2017-09-14 22:21:00 +03:00
}
return [
'name' => 'required|string',
'email' => 'required|email|unique:users,email,' . $id . ',id,deleted_at,NULL',
2020-10-05 11:11:59 +03:00
'password' => $password . 'confirmed',
'companies' => $companies,
'roles' => $roles,
2019-11-16 10:21:14 +03:00
'picture' => $picture,
2017-09-14 22:21:00 +03:00
];
}
}