public function postAdminLesson(Request $request) { if (Auth::user()->type == 'admin') { $student = User::where(['type' => 'student', 'email' => $request->input('studentemail')])->first(); if (count($student) != 0) { $tutor = User::where(['type' => 'tutor', 'email' => $request->input('tutoremail')])->first(); if (count($tutor) == 0) { return redirect()->route('admin.lessons')->with('msg', 'Tutor Not Found........'); } } else { return redirect()->route('admin.lessons')->with('msg', 'Student Not Found........'); } $amount = $request->input('duration') * $tutor->tutorinfo->amount_per_hour; Lesson::create(['studentid' => $student->id, 'tutorid' => $tutor->id, 'date' => $request->input('date'), 'time' => $request->input('time'), 'duration' => $request->input('duration'), 'amount' => $amount]); return redirect()->route('admin.lessons')->with('msg', 'Successfully Added Lesson........'); } else { return redirect()->route('auth.login'); } }