/**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show(Request $request, $id)
 {
     //
     $data = $request->all();
     $id_period = $data['id_period'];
     if ($id == 1) {
         // Add code for load teacher whitout period
         $teachers = \App\Project::leftJoin('registry_projects', function ($join) use($id_period) {
             $join->on('projects.id', '=', 'registry_projects.id_project')->where('registry_projects.id_period', '=', $id_period);
         })->whereNull('registry_projects.id_project')->Where('projects.active', 1)->select('projects.id', 'projects.name')->get()->toJson();
         //	dd($teacher);
     } else {
         // Add code for load teacher whit period
         $teachers = \App\RegistryProject::Join('projects', 'projects.id', '=', 'registry_projects.id_project')->select('registry_projects.id as id_registry_project', 'projects.id', 'projects.name')->Where('registry_projects.id_period', $id_period)->get()->toJson();
     }
     $status = count(json_decode($teachers, true)) > 0 ? true : false;
     if ($request->ajax()) {
         return response()->json(['status' => $status, 'data' => $teachers]);
     }
 }
 public function getTop10ProjectsWithMostFeedbacks()
 {
     return Project::leftJoin('project_user', 'projects.id', '=', 'project_user.project_id')->select('projects.name', DB::raw('COUNT(project_user.user_id) as aggregate'))->groupBy('id')->orderBy('aggregate', 'DESC')->limit(10)->get()->toJSON();
 }
Example #3
0
 /**
  * Projects associated with the user
  *
  * Returns a Builder instance rather than a relation because of
  * the manual left join to client_user. A hasManyThrough relation
  * would not work because of the many-to-many relationship between
  * users and clients.
  *
  * @return Builder
  */
 public function projects()
 {
     $query = Project::leftJoin('client_user', 'client_user.client_id', '=', 'projects.client_id');
     $query->where('client_user.user_id', $this->getKey());
     return $query;
 }
 public function opciones()
 {
     $projects = Project::leftJoin('homes', 'homes.project_id', '=', 'projects.id')->select('projects.*', DB::raw('count(*) as n_casas'))->groupBy('projects.id')->get();
     return view('admin.project.option', compact('projects'));
 }