1 <?php namespace Oxbow\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 $roleId = \Setting::get('registration-role');
51 if ($roleId === false) {
52 $roleId = $this->role->getDefault()->id;
55 $user->attachRoleId($roleId);
60 * Checks if the give user is the only admin.
64 public function isOnlyAdmin(User $user)
66 if ($user->role->name != 'admin') {
70 $adminRole = $this->role->where('name', '=', 'admin')->first();
71 if (count($adminRole->users) > 1) {
79 * Create a new basic instance of user.
83 public function create(array $data)
85 return $this->user->create([
86 'name' => $data['name'],
87 'email' => $data['email'],
88 'password' => bcrypt($data['password'])