コード例 #1
0
 public function registerUser($name, $email, $password)
 {
     $user = new User();
     $user->password = is_null($password) ? null : bcrypt($password);
     $user->email = $email;
     $user->save();
     $profile = new Profile();
     $profile->name = $name;
     $profile->user_id = $user->id;
     $profile->description = "";
     $profile->save();
     return $user;
 }
コード例 #2
0
 /**
  * Show the profile for the given user.
  *
  * @param  int  $id
  * @return Response
  */
 public function showProfile()
 {
     $user = Profile::all();
     print_r($user);
     die;
     return view('profile')->with('user', $user);
 }
コード例 #3
0
 public function testbelongsToSave()
 {
     /*
     *	Profile BelongsTo User
     */
     $user1 = User::create(['name' => 'newUser']);
     $profile = Profile::create();
     $profile->User = $user1;
     print_r($profile);
     $this->assertEquals(true, $profile->save());
     $this->assertEquals($profile->user_id, $user1->id);
     /*
     *	本当にセーブできたかreadで確認
     */
     $savedUser1 = User::read($profile->User->id);
     $this->assertEquals($profile->User->name, $savedUser1->name);
     $this->assertEquals($profile->User->id, $savedUser1->id);
     /*
     *	Comment BelongsTo User
     */
     $user2 = User::newRecord(['name' => 'newUser2']);
     $comment = Comment::create();
     $comment->User = $user2;
     $this->assertEquals(true, $comment->save());
     //print_r($comment);
     $this->assertEquals($comment->user_id, $user2->id);
     /*
     *	本当にセーブできたかreadで確認
     */
     $savedUser2 = User::read($comment->User->id);
     $this->assertEquals($comment->User->name, $savedUser2->name);
     $this->assertEquals($comment->User->id, $savedUser2->id);
 }