64 lines
2.1 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;
use Illuminate\Support\Str;
2017-12-16 16:02:31 +03:00
class Profile extends FormRequest
{
/**
* 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';
2021-07-18 17:12:37 +03:00
if ($this->files->get('picture')) {
$picture = 'mimes:' . config('filesystems.mimes')
. '|between:0,' . config('filesystems.max_size') * 1024
. '|dimensions:max_width=' . config('filesystems.max_width') . ',max_height=' . config('filesystems.max_height');
2019-11-16 10:21:14 +03:00
}
2017-12-16 16:02:31 +03:00
2022-06-01 10:15:55 +03:00
$email = 'required|email:rfc,dns|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
}
$change_password = $this->request->get('change_password') == true || $this->request->get('change_password') != null;
$current_password = $change_password ? '|current_password' : '';
$password = $change_password ? '|confirmed' : '';
2017-12-16 16:02:31 +03:00
return [
'name' => 'required|string',
'email' => $email,
'current_password' => 'required_if:change_password,true' . $current_password,
'password' => 'required_if:change_password,true' . $password,
'picture' => $picture,
];
}
public function messages()
{
$picture_dimensions = trans('validation.custom.invalid_dimension', [
'attribute' => Str::lower(trans_choice('general.pictures', 1)),
'width' => config('filesystems.max_width'),
'height' => config('filesystems.max_height'),
]);
return [
'picture.dimensions' => $picture_dimensions,
2017-12-16 16:02:31 +03:00
];
}
}