52 lines
1.2 KiB
PHP
Raw Normal View History

2017-12-16 16:02:31 +03:00
<?php
2019-11-16 10:21:14 +03:00
namespace App\Http\Requests\Portal;
2017-12-16 16:02:31 +03:00
use Illuminate\Foundation\Http\FormRequest;
class Profile 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
$id = user()->getAttribute('id');
$picture = 'nullable';
if ($this->request->get('picture', null)) {
$picture = 'mimes:' . config('filesystems.mimes') . '|between:0,' . config('filesystems.max_size') * 1024;
}
2017-12-16 16:02:31 +03:00
2021-04-29 16:09:10 +03:00
$email = 'required|email|unique:users,email,' . $id . ',id,deleted_at,NULL';
2021-04-29 15:19:05 +03:00
if (user()->contact) {
2021-04-29 16:09:10 +03:00
$email .= '|unique:contacts,NULL,'
. user()->contact->id . ',id'
. ',company_id,' . company_id()
. ',type,customer'
. ',deleted_at,NULL';
2021-04-29 15:19:05 +03:00
}
2017-12-16 16:02:31 +03:00
return [
'name' => 'required|string',
2021-04-29 15:19:05 +03:00
'email' => $email,
2017-12-16 16:02:31 +03:00
'password' => 'confirmed',
2019-11-16 10:21:14 +03:00
'picture' => $picture,
2017-12-16 16:02:31 +03:00
];
}
}