public function getFromUserId($user_id) { // checks if the user exists try { User::findOrFail($user_id); } catch (ModelNotFoundException $e) { throw new UserNotFoundException(); } // gets the profile $profile = $this->model->where('user_id', '=', $user_id)->get(); // check if the profile exists if ($profile->isEmpty()) { throw new ProfileNotFoundException(); } return $profile->first(); }
/** * @param $user */ protected function assertUserHasProfile($user) { $user_profile = User::find($user->id)->user_profile()->first(); $this->assertEquals($user_profile->user_id, $user->id); }
/** * @test **/ public function canAddAPermission() { $user_created = $this->make('Jacopo\\Authentication\\Models\\User', $this->getUserStub()); $permission_name = "_perm"; $input = ["permissions" => $permission_name, "id" => $user_created[0]->id, "operation" => $this->add_operation]; $this->route('POST', 'users.edit.permission', $input); $user_found = User::find($user_created[0]->id); $this->assertUserHasPermission($user_found, $permission_name); }
private function createUserWithPerm(array $perm) { DB::table('users')->insert(["email" => $this->faker->email(), "password" => $this->faker->text(10), "activated" => 1, "permissions" => json_encode($perm), "created_at" => $this->getNowDateTime(), "updated_at" => $this->getNowDateTime()]); return User::first(); }
protected function assertEmptyUsers() { $this->assertNull(User::first()); }
protected function initializeUserHasher() { User::setHasher(App::make('sentry.hasher')); return $this; }
/** * Remove a group to the user * * @param $id group id * @throws \Jacopo\Authentication\Exceptions\UserNotFoundException */ public function removeGroup($user_id, $group_id) { try { $group = Group::findOrFail($group_id); $user = User::findOrFail($user_id); $user->removeGroup($group); } catch (ModelNotFoundException $e) { throw new NotFoundException(); } }