Add customer/user's email validation

This commit is contained in:
Burak Çakırel
2021-04-29 15:19:05 +03:00
parent beaa84e380
commit 09f83c2044
3 changed files with 52 additions and 4 deletions

View File

@ -3,6 +3,7 @@
namespace App\Http\Requests\Common;
use App\Abstracts\Http\FormRequest;
use Illuminate\Validation\Rule;
class Contact extends FormRequest
{
@ -23,7 +24,7 @@ class Contact extends FormRequest
*/
public function rules()
{
$email = '';
$email = [];
$required = '';
$type = $this->request->get('type', 'customer');
@ -43,7 +44,18 @@ class Contact extends FormRequest
}
if (!empty($this->request->get('email'))) {
$email = 'email|unique:contacts,NULL,' . $id . ',id,company_id,' . $company_id . ',type,' . $type . ',deleted_at,NULL';
$email[] = 'email';
$email[] = Rule::unique('contacts')
->ignore($id)
->where('company_id', $company_id)
->where('type', $type)
->where('deleted_at');
if (isset($model) && $this->$model->user_id) {
$email[] = Rule::unique('users')
->ignore($this->$model->user_id)
->where('deleted_at');
}
}
return [