only(['name', 'email', 'phone']); $admin = CompanyAdmin::where('user_id', auth()->id()); if (!$admin->count()) { abort(404); return; } $admin = $admin->first(); if (!$this->isUnique($request->email, $request->phone)) { return back()->with('error', __('Agent is not unique')); } if ($user = User::create($request->all())) { $user->setForcedPassword(); $agent = Agent::create([ 'user_id' => $user->id, 'company_id' => $admin->company_id ]); } return to_route('company.agents.table'); } public function isUnique($email, $phone) { if (User::where('email', $email)->count() || User::where('phone', $phone)->count()) { return false; } return true; } }