public function test_index_returns_classrooms_by_get() { DB::statement('SET FOREIGN_KEY_CHECKS=0;'); Classroom::where('id', '>=', 1)->delete(); DB::statement('SET FOREIGN_KEY_CHECKS=1;'); $classrooms = factory(Classroom::class, 3)->create(); $this->get('api/v1/classroom'); $this->seeStatusCode(200); foreach ($classrooms as $classroom) { $this->seeJson(['name' => $classroom->name]); } }
/** * Determine if the user is authorized to make this request. * * @return bool */ public function authorize() { $id = $this->route('classroom_id'); return Classroom::where('id', $id)->exists(); }