コード例 #1
0
ファイル: GoalTest.php プロジェクト: nvanselow/tsny-students
 public function testToggleGoal()
 {
     $goal = \Tsny\Models\Goal::find(1);
     $this->post('api/goal/1/toggle');
     $this->seeInDatabase('goals', ['id' => 1, 'complete' => !$goal->complete]);
     $this->post('api/goal/1/toggle');
     $this->seeInDatabase('goals', ['id' => 1, 'complete' => $goal->complete]);
 }
コード例 #2
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Goal::truncate();
     $faker = \Faker\Factory::create();
     Goal::create(['student_id' => 1, 'user_id' => 1, 'description' => $faker->sentence(), 'complete' => true]);
     Goal::create(['student_id' => 1, 'user_id' => 2, 'description' => $faker->sentence()]);
     Goal::create(['student_id' => 1, 'description' => $faker->sentence()]);
     Goal::create(['student_id' => 2, 'user_id' => 3, 'description' => $faker->sentence()]);
     Goal::create(['student_id' => 3, 'description' => $faker->sentence()]);
 }
コード例 #3
0
 public function toggle($goal_id)
 {
     $goal = Goal::where('id', $goal_id)->select('id', 'complete')->first();
     $goal->complete = !$goal->complete;
     return $goal->save() ? Response::json($goal) : Response::json(['message' => 'There was a problem updating the goal.'], 400);
 }