1 <?php namespace BookStack\Repos;
14 * UserRepo constructor.
17 public function __construct(User $user, Role $role)
24 * @param string $email
27 public function getByEmail($email)
29 return $this->user->where('email', '=', $email)->first();
36 public function getById($id)
38 return $this->user->findOrFail($id);
42 * Creates a new user and attaches a role to them.
46 public function registerNew(array $data)
48 $user = $this->create($data);
49 $this->attachDefaultRole($user);
54 * Give a user the default role. Used when creating a new user.
57 public function attachDefaultRole($user)
59 $roleId = \Setting::get('registration-role');
60 if ($roleId === false) $roleId = $this->role->getDefault()->id;
61 $user->attachRoleId($roleId);
65 * Checks if the give user is the only admin.
69 public function isOnlyAdmin(User $user)
71 if ($user->role->name != 'admin') {
75 $adminRole = $this->role->where('name', '=', 'admin')->first();
76 if (count($adminRole->users) > 1) {
84 * Create a new basic instance of user.
88 public function create(array $data)
90 return $this->user->create([
91 'name' => $data['name'],
92 'email' => $data['email'],
93 'password' => bcrypt($data['password'])
98 * Remove the given user from storage, Delete all related content.
101 public function destroy(User $user)
103 $user->socialAccounts()->delete();