create agent without email
This commit is contained in:
parent
6f63bd9118
commit
487c38d797
@ -8,11 +8,14 @@
|
||||
use App\Models\Agent\Agent;
|
||||
use App\Models\User;
|
||||
|
||||
use App\Notifications\UserRegistered;
|
||||
|
||||
|
||||
class CreateAgentController extends Controller
|
||||
{
|
||||
public function __invoke(Request $request)
|
||||
{
|
||||
$request->only(['name', 'email', 'phone']);
|
||||
//dd($request->sendToEmail);
|
||||
$admin = CompanyAdmin::where('user_id', auth()->id());
|
||||
if (!$admin->count())
|
||||
{
|
||||
@ -35,7 +38,6 @@ public function __invoke(Request $request)
|
||||
else
|
||||
{
|
||||
$user = $user = User::create($request->all());
|
||||
$user->setForcedPassword();
|
||||
}
|
||||
|
||||
if ($user)
|
||||
@ -46,6 +48,17 @@ public function __invoke(Request $request)
|
||||
'company_id' => $admin->company_id
|
||||
]);
|
||||
}
|
||||
|
||||
if ($request->sendToEmail)
|
||||
{
|
||||
$user->setForcedPassword();
|
||||
}
|
||||
else
|
||||
{
|
||||
$password = $user->setForcedPassword(false);
|
||||
$admin->notify(instance: new UserRegistered($user->email, password: $password));
|
||||
return redirect()->route('company.agents.table')->with('success', 'thank you');
|
||||
}
|
||||
return to_route('company.agents.table');
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,13 +7,16 @@
|
||||
use App\Notifications\UserRegistered;
|
||||
|
||||
trait ForcedPassword
|
||||
{
|
||||
public function setForcedPassword($sendToEmail = true)
|
||||
{
|
||||
public function setForcedPassword()
|
||||
{
|
||||
$newPassword = Str::password(8);
|
||||
$this->password = Hash::make($newPassword);
|
||||
$this->save();
|
||||
$this->notify(instance: new UserRegistered($this->email, password: $newPassword));
|
||||
return true;
|
||||
if ($sendToEmail)
|
||||
{
|
||||
$this->notify(instance: new UserRegistered($this->email, password: $newPassword));
|
||||
}
|
||||
}
|
||||
return $newPassword;
|
||||
}
|
||||
}
|
||||
@ -64,6 +64,13 @@
|
||||
<label for="agentPhone" class="form-label">Телефон</label>
|
||||
<input type="text" class="form-control" id="agentPhone" name="phone">
|
||||
</div>
|
||||
|
||||
<div class="mb-3 form-check form-switch">
|
||||
<input class="form-check-input" type="checkbox" role="switch" id="sendEmailSwitch"
|
||||
name="sendToEmail" checked>
|
||||
<label class="form-check-label" for="sendEmailSwitch">Отправить учетные данные на электронную
|
||||
почту</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Отмена</button>
|
||||
|
||||
@ -86,6 +86,9 @@
|
||||
@include('left-panel')
|
||||
</div>
|
||||
<div class="col-10 px-0 px-md-4">
|
||||
@if (session('success'))
|
||||
{{ session('success') }}
|
||||
@endif
|
||||
@foreach ($errors->all() as $error)
|
||||
{{ $error }}
|
||||
@endforeach
|
||||
|
||||
Loading…
Reference in New Issue
Block a user