Change validation rules to string
This commit is contained in:
parent
09f83c2044
commit
bee4056c3a
@ -2,13 +2,10 @@
|
||||
|
||||
namespace App\Http\Requests\Auth;
|
||||
|
||||
use App\Traits\Contacts;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class User extends FormRequest
|
||||
{
|
||||
use Contacts;
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
@ -33,7 +30,7 @@ class User extends FormRequest
|
||||
$picture = 'mimes:' . config('filesystems.mimes') . '|between:0,' . config('filesystems.max_size') * 1024;
|
||||
}
|
||||
|
||||
$email = ['required', 'email'];
|
||||
$email = 'required|email';
|
||||
|
||||
if ($this->getMethod() == 'PATCH') {
|
||||
// Updating user
|
||||
@ -43,11 +40,11 @@ class User extends FormRequest
|
||||
$roles = $this->user->can('read-auth-roles') ? 'required' : '';
|
||||
|
||||
if ($this->user->contact) {
|
||||
$email[] = Rule::unique('contacts')
|
||||
->ignore($this->user->contact->id)
|
||||
->where('company_id', company_id())
|
||||
->where('type', $this->getCustomerTypes())
|
||||
->where('deleted_at');
|
||||
$email .= '|unique:contacts,NULL,'
|
||||
. $this->user->contact->id . ',id'
|
||||
. ',company_id,' . company_id()
|
||||
. ',type,customer'
|
||||
. ',deleted_at,NULL';
|
||||
}
|
||||
} else {
|
||||
// Creating user
|
||||
@ -57,7 +54,7 @@ class User extends FormRequest
|
||||
$roles = 'required';
|
||||
}
|
||||
|
||||
$email[] = Rule::unique('users')->ignore($id)->where('deleted_at');
|
||||
$email .= '|unique:users,email,' . $id . ',id,deleted_at,NULL';
|
||||
|
||||
return [
|
||||
'name' => 'required|string',
|
||||
|
@ -3,7 +3,6 @@
|
||||
namespace App\Http\Requests\Common;
|
||||
|
||||
use App\Abstracts\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class Contact extends FormRequest
|
||||
{
|
||||
@ -24,7 +23,7 @@ class Contact extends FormRequest
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
$email = [];
|
||||
$email = '';
|
||||
$required = '';
|
||||
|
||||
$type = $this->request->get('type', 'customer');
|
||||
@ -44,17 +43,14 @@ class Contact extends FormRequest
|
||||
}
|
||||
|
||||
if (!empty($this->request->get('email'))) {
|
||||
$email[] = 'email';
|
||||
$email[] = Rule::unique('contacts')
|
||||
->ignore($id)
|
||||
->where('company_id', $company_id)
|
||||
->where('type', $type)
|
||||
->where('deleted_at');
|
||||
$email .= 'email|unique:contacts,NULL,'
|
||||
. $id . ',id'
|
||||
. ',company_id,' . $company_id
|
||||
. ',type,' . $type
|
||||
. ',deleted_at,NULL';
|
||||
|
||||
if (isset($model) && $this->$model->user_id) {
|
||||
$email[] = Rule::unique('users')
|
||||
->ignore($this->$model->user_id)
|
||||
->where('deleted_at');
|
||||
$email .= '|unique:users,NULL,' . $this->$model->user_id . ',id,deleted_at,NULL';
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,14 +2,10 @@
|
||||
|
||||
namespace App\Http\Requests\Portal;
|
||||
|
||||
use App\Traits\Contacts;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class Profile extends FormRequest
|
||||
{
|
||||
use Contacts;
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
@ -35,20 +31,14 @@ class Profile extends FormRequest
|
||||
$picture = 'mimes:' . config('filesystems.mimes') . '|between:0,' . config('filesystems.max_size') * 1024;
|
||||
}
|
||||
|
||||
$email = [
|
||||
'required',
|
||||
'email',
|
||||
Rule::unique('users')
|
||||
->ignore($id)
|
||||
->where('deleted_at'),
|
||||
];
|
||||
$email = 'required|email|unique:users,email,' . $id . ',id,deleted_at,NULL';
|
||||
|
||||
if (user()->contact) {
|
||||
$email[] = Rule::unique('contacts')
|
||||
->ignore(user()->contact->id)
|
||||
->where('company_id', company_id())
|
||||
->where('type', $this->getCustomerTypes())
|
||||
->where('deleted_at');
|
||||
$email .= '|unique:contacts,NULL,'
|
||||
. user()->contact->id . ',id'
|
||||
. ',company_id,' . company_id()
|
||||
. ',type,customer'
|
||||
. ',deleted_at,NULL';
|
||||
}
|
||||
|
||||
return [
|
||||
|
Loading…
x
Reference in New Issue
Block a user