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\Agent\Agent;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
|
|
||||||
|
use App\Notifications\UserRegistered;
|
||||||
|
|
||||||
|
|
||||||
class CreateAgentController extends Controller
|
class CreateAgentController extends Controller
|
||||||
{
|
{
|
||||||
public function __invoke(Request $request)
|
public function __invoke(Request $request)
|
||||||
{
|
{
|
||||||
$request->only(['name', 'email', 'phone']);
|
//dd($request->sendToEmail);
|
||||||
$admin = CompanyAdmin::where('user_id', auth()->id());
|
$admin = CompanyAdmin::where('user_id', auth()->id());
|
||||||
if (!$admin->count())
|
if (!$admin->count())
|
||||||
{
|
{
|
||||||
@ -35,7 +38,6 @@ public function __invoke(Request $request)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
$user = $user = User::create($request->all());
|
$user = $user = User::create($request->all());
|
||||||
$user->setForcedPassword();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($user)
|
if ($user)
|
||||||
@ -46,6 +48,17 @@ public function __invoke(Request $request)
|
|||||||
'company_id' => $admin->company_id
|
'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');
|
return to_route('company.agents.table');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,12 +8,15 @@
|
|||||||
|
|
||||||
trait ForcedPassword
|
trait ForcedPassword
|
||||||
{
|
{
|
||||||
public function setForcedPassword()
|
public function setForcedPassword($sendToEmail = true)
|
||||||
{
|
{
|
||||||
$newPassword = Str::password(8);
|
$newPassword = Str::password(8);
|
||||||
$this->password = Hash::make($newPassword);
|
$this->password = Hash::make($newPassword);
|
||||||
$this->save();
|
$this->save();
|
||||||
|
if ($sendToEmail)
|
||||||
|
{
|
||||||
$this->notify(instance: new UserRegistered($this->email, password: $newPassword));
|
$this->notify(instance: new UserRegistered($this->email, password: $newPassword));
|
||||||
return true;
|
}
|
||||||
|
return $newPassword;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -64,6 +64,13 @@
|
|||||||
<label for="agentPhone" class="form-label">Телефон</label>
|
<label for="agentPhone" class="form-label">Телефон</label>
|
||||||
<input type="text" class="form-control" id="agentPhone" name="phone">
|
<input type="text" class="form-control" id="agentPhone" name="phone">
|
||||||
</div>
|
</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>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Отмена</button>
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Отмена</button>
|
||||||
|
|||||||
@ -86,6 +86,9 @@
|
|||||||
@include('left-panel')
|
@include('left-panel')
|
||||||
</div>
|
</div>
|
||||||
<div class="col-10 px-0 px-md-4">
|
<div class="col-10 px-0 px-md-4">
|
||||||
|
@if (session('success'))
|
||||||
|
{{ session('success') }}
|
||||||
|
@endif
|
||||||
@foreach ($errors->all() as $error)
|
@foreach ($errors->all() as $error)
|
||||||
{{ $error }}
|
{{ $error }}
|
||||||
@endforeach
|
@endforeach
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user