Beispiel #1
0
 public function activate() : User
 {
     if ($this->status->doesntEqual(UserStatus::WAITING_FOR_APPROVAL())) {
         throw new UserIsAlreadyActivated();
     }
     $this->status = UserStatus::ACTIVE();
     return $this;
 }
 public function seedAdmins()
 {
     $users = ['Willem' => 'Van Bockstal', 'Freek' => 'Van der Herten', 'Rogier' => 'De Boevé', 'Sebastian' => 'De Deyne'];
     collect($users)->each(function ($lastName, $firstName) {
         $password = app()->environment('local') ? strtolower($firstName) : string()->random();
         User::create(['email' => strtolower($firstName) . '@spatie.be', 'password' => bcrypt($password), 'first_name' => $firstName, 'last_name' => $lastName, 'role' => UserRole::ADMIN(), 'status' => UserStatus::ACTIVE()]);
     });
 }
 public function store(BackUserRequest $request)
 {
     $user = new User();
     $user->email = $request->get('email');
     $user->first_name = $request->get('first_name');
     $user->last_name = $request->get('last_name');
     $user->locale = $request->get('locale', 'nl');
     if ($request->has('password')) {
         $user->password = $request->get('password');
     }
     $user->role = UserRole::ADMIN();
     $user->status = UserStatus::ACTIVE();
     $user->save();
     $eventDescription = $this->getEventDescriptionFor('created', $user);
     activity()->on($user)->log($eventDescription);
     flash()->success(strip_tags($eventDescription) . '. ' . fragment('back.administrators.passwordMailSent'));
     event(new UserCreated($user));
     return redirect(action('Back\\AdministratorsController@index', ['role' => $user->role]));
 }
<?php

use App\Services\Auth\Back\Enums\UserRole;
use App\Services\Auth\Back\Enums\UserStatus;
use App\Services\Auth\Back\User;
$factory->define(User::class, function () {
    $person = faker()->person();
    return ['first_name' => $person['firstName'], 'last_name' => $person['lastName'], 'email' => $person['email'], 'password' => faker()->password, 'locale' => 'nl', 'role' => UserRole::ADMIN(), 'status' => UserStatus::ACTIVE()];
});