public function testGenerateCode()
 {
     $code = User::generateCode('activation_code');
     $this->assertEquals(strlen($code), 25);
     $code = User::generateCode('activation_code', 35);
     $this->assertEquals(strlen($code), 35);
     try {
         $code = User::generateCode('not_valid_key');
         $this->assertTrue(false, 'Generated a code for an invalid column');
     } catch (Exception $e) {
         $this->assertTrue($e instanceof InvalidArgumentException);
     }
 }
 public function update(ScholarshipRequest $request, Scholarship $scholarships)
 {
     foreach ($request->all()['data']['attributes'] as $key => $value) {
         if (isset($scholarships->{$key})) {
             $scholarships->{$key} = $value;
         }
     }
     // fetch scholarshiped by user
     $updatedBy = User::findOrFail($request->all()['data']['relationships']['updated_by']['data']['id']);
     $scholarships->updated_by = $updatedBy->id;
     $scholarships->save();
     $resource = new Item($scholarships, new ScholarshipTransformer(), 'scholarships');
     return $this->fractal()->createData($resource)->toJson();
 }
 public function update(PostRequest $request, Post $posts)
 {
     foreach ($request->all()['data']['attributes'] as $key => $value) {
         if (isset($posts->{$key})) {
             $posts->{$key} = $value;
         }
     }
     // fetch posted by user
     $postedBy = User::findOrFail($request->all()['data']['relationships']['posted_by']['data']['id']);
     $posts->posted_by = $postedBy->id;
     $posts->save();
     $resource = new Item($posts, new PostTransformer(), 'posts');
     return $this->fractal()->createData($resource)->toJson();
 }
 public function store(UserRequirementRequest $request)
 {
     $data = $request->all()['data'];
     // create the user requirement
     $userRequirement = new UserRequirement();
     foreach ($data['attributes'] as $key => $value) {
         $userRequirement->{$key} = $value;
     }
     // fetch user
     $user = User::findOrFail($data['relationships']['user']['data']['id']);
     // create the user profile
     $user->requirements()->save($userRequirement);
     $resource = new Item($userRequirement, new UserRequirementTransformer(), 'users');
     return response()->json($this->fractal()->createData($resource)->toArray(), Response::HTTP_CREATED);
 }
 public function testPatchUsers()
 {
     $userObject = factory(User::class)->create();
     $userData = ['data' => ['type' => 'users', 'attributes' => $userObject->toArray() + ['birthday' => $userObject->birthday->format('Y-m-d'), 'password' => $userObject->password]]];
     $userData['data']['attributes']['first_name'] = 'niweuogbnwiuebg';
     $userData = json_encode($userData);
     $response = $this->callPatch(self::API_URL . $userObject->id, $userData);
     $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
     $this->assertNotNull($user = json_decode($response->getContent())->data);
     $this->assertNotEmpty($user->id);
     // test to make sure the user was created
     try {
         $updatedUser = User::findOrFail($userObject->id);
         $this->assertEquals('niweuogbnwiuebg', $updatedUser->first_name);
     } catch (Exception $e) {
         $this->assertTrue(false, 'User account not found');
     }
 }
 public function update(TeamMemberRequest $request, TeamMember $team_members)
 {
     $data = $request->all();
     foreach ($data['data']['attributes'] as $key => $value) {
         if (isset($team_members->{$key})) {
             $team_members->{$key} = $value;
         }
     }
     // fetch team
     $team = Team::findOrFail($data['data']['relationships']['team']['data']['id']);
     $team_members->team_id = $team->id;
     // fetch user
     $user = User::findOrFail($data['data']['relationships']['user']['data']['id']);
     $team_members->user_id = $user->id;
     $team_members->save();
     $resource = new Item($team_members, new TeamMemberTransformer(), 'team-members');
     return $this->fractal()->createData($resource)->toJson();
 }
 public function destroy(User $users)
 {
     $users->delete();
     return response()->json('', Response::HTTP_NO_CONTENT);
 }