2018-10-06 09:43:58 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Traits;
|
|
|
|
|
2019-07-14 14:18:15 +01:00
|
|
|
use App\Notifications\UserSelfActivated;
|
2018-10-06 09:43:58 +01:00
|
|
|
use App\User;
|
2018-11-19 13:26:44 +00:00
|
|
|
use App\UserActivity;
|
2018-10-06 09:43:58 +01:00
|
|
|
|
|
|
|
trait ActivatesUsers
|
|
|
|
{
|
2018-11-19 13:26:44 +00:00
|
|
|
private function logActivatedActivity(User $createdUser, $activityDateTime = null)
|
|
|
|
{
|
|
|
|
if (is_null($activityDateTime))
|
|
|
|
{
|
|
|
|
$activityDateTime = new \DateTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
$userActivity = new UserActivity();
|
|
|
|
$userActivity->user_id = $createdUser->id;
|
|
|
|
$userActivity->activity_at = $activityDateTime;
|
|
|
|
$userActivity->type = 'user.created';
|
|
|
|
$userActivity->save();
|
|
|
|
}
|
|
|
|
|
2018-10-06 09:43:58 +01:00
|
|
|
private function sendUserActivatedEmails(User $createdUser)
|
|
|
|
{
|
|
|
|
$adminUsers = User::where('is_admin', true)->get();
|
|
|
|
|
|
|
|
/** @var User $adminUser */
|
|
|
|
foreach ($adminUsers as $adminUser)
|
|
|
|
{
|
2019-07-14 14:18:15 +01:00
|
|
|
$adminUser->notify(new UserSelfActivated($createdUser));
|
2018-10-06 09:43:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|