Advertisement
Ostap34PHP

Untitled

Jan 25th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.50 KB | None | 0 0
  1.     /**
  2.      * Show the application dashboard.
  3.      *
  4.      * @return \Illuminate\Http\Response
  5.      */
  6.     public function index()
  7.     {
  8.         $completed_lessons_count =
  9.             DB::table('lesson_user')->selectRaw('COUNT(lesson_id)')->whereIn('lesson_id', function ($query) {
  10.                 $query->select('id')->from('lessons')->whereIn('section_id', function ($query) {
  11.                     $query->select('id')->from('sections')->whereRaw('`sections`.`course_id` = `courses`.`id`');
  12.                 });
  13.             });
  14.  
  15.         $lessons_count = Lesson::selectRaw('COUNT(id)')->whereIn('section_id', function ($query) {
  16.             $query->select('id')->from('sections')->whereRaw('`sections`.`course_id` = `courses`.`id`');
  17.         });
  18.  
  19.         $last_completed_lesson_id = DB::table('lesson_user')->select('lesson_id')->whereIn('lesson_id', function ($query) {
  20.             $query->select('id')->from('lessons')->whereIn('section_id', function ($query) {
  21.                 $query->select('id')->from('sections')->whereRaw('`sections`.`course_id` = `courses`.`id`');
  22.             });
  23.         })->orderBy('lesson_id', 'desk')->limit(1);
  24.  
  25.         $courses = auth()->user()->courses()
  26.             ->select('*')
  27.             ->selectSub($completed_lessons_count, 'completed_lessons_count')
  28.             ->selectSub($lessons_count, 'lessons_count')
  29.             ->selectSub($last_completed_lesson_id, 'last_completed_lesson_id')
  30.             ->get();
  31.  
  32.         return view('home', ['courses' => $courses]);
  33.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement