/** * Get sepecified resource or fail with HTTP 404 * * @param int $id * @return \Illuminate\Database\Eloquent\Model */ public static function getStudentOrFail($id) { // in case student is not found Session::flash('http_status', 'Student not found.'); // get the student $student = \ATC\Student::findOrFail($id); // student found Session::remove('http_status'); return $student; }
/** * Run the database seeds. * * @return void */ public function run() { // get ids of all the students $student_ids = \ATC\Student::lists('id'); $coursesPerStudent = 4; // create Faker object $faker = Faker::create(); foreach ($student_ids as $student_id) { for ($i = 0; $i < $coursesPerStudent; $i++) { // create model object $course = new \ATC\Course(); $course->name = $faker->regexify('[A-Z][A-Z][A-Z][A-Z]') . ' ' . $faker->numberBetween(100, 1999); $course->year = Carbon\Carbon::now()->year; $course->term_id = 1; $course->student_id = $student_id; $course->save(); // insert new course in table } } }
*/ Route::get('/google/authorize', function () { return SocialAuth::authorize('google'); }); Route::get('/google/login', function () { try { SocialAuth::login('google', function ($user, $userDetails) { // is "host domain" correct? if ($userDetails->raw['hd'] == 'cognize.org') { // is user staff? if ($staffCheck = \ATC\Staff::where('external_id', '=', $userDetails->email)->first()) { $user->email = $userDetails->email; $user->name = $userDetails->full_name; $user->role = 'staff'; $user->save(); } elseif ($studentCheck = \ATC\Student::where('external_id', '=', $userDetails->email)->first()) { $user->email = $userDetails->email; $user->name = $userDetails->full_name; $user->role = 'student'; $user->save(); } else { Session::flash('http_status', 'No such user'); abort(403, 'Forbbiden'); } } else { Session::flash('http_status', 'Domain not allowed'); abort(403, 'Forbbiden'); } }); } catch (ApplicationRejectedException $e) { // User rejected application
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { // in case it's not found Session::flash('http_status', 'Student not found.'); // get a student $student = \ATC\Student::findOrFail($id); // delete student, will cascade to delete their courses $student->delete(); Session::flash('flash_message', $student->initials . ' deleted'); // go to list view on staff member's home page return redirect('/'); }
/** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function showStudentCourse($id) { // get id of logged in student $studentId = \ATC\Student::where('external_id', '=', \Auth::user()->email)->get()->first()->id; return $this->show($studentId, $id); }