1 <?php namespace BookStack\Repos;
15 * UserRepo constructor.
18 public function __construct(User $user, Role $role)
25 * @param string $email
28 public function getByEmail($email)
30 return $this->user->where('email', '=', $email)->first();
37 public function getById($id)
39 return $this->user->findOrFail($id);
43 * Creates a new user and attaches a role to them.
47 public function registerNew(array $data)
49 $user = $this->create($data);
50 $this->attachDefaultRole($user);
55 * Give a user the default role. Used when creating a new user.
58 public function attachDefaultRole($user)
60 $roleId = Setting::get('registration-role');
61 if ($roleId === false) $roleId = $this->role->getDefault()->id;
62 $user->attachRoleId($roleId);
66 * Checks if the give user is the only admin.
70 public function isOnlyAdmin(User $user)
72 if ($user->role->name != 'admin') {
76 $adminRole = $this->role->where('name', '=', 'admin')->first();
77 if (count($adminRole->users) > 1) {
85 * Create a new basic instance of user.
89 public function create(array $data)
91 return $this->user->forceCreate([
92 'name' => $data['name'],
93 'email' => $data['email'],
94 'password' => bcrypt($data['password'])
99 * Remove the given user from storage, Delete all related content.
102 public function destroy(User $user)
104 $user->socialAccounts()->delete();