/** * Display the specified resource. * * @param int $id * @return Response */ public function show(Request $request, $id) { // $data = $request->all(); //dd($data); $id_period = $data['id_period']; $id_company = $data['id_company']; if ($id == 1) { // Add code for load teacher whitout period /* $teachers = \App\RegistryStudent::Join('users','users.id','=','registry_students.id_student') ->leftJoin('registry_companies', 'users.id', '=', 'registry_companies.id_student') ->select('registry_students.id as id_registry_student','users.id','users.first_name','users.last_name','users.type') ->whereNull('registry_companies.id_student') ->Where('registry_students.id_period',$id_period) ->get()->toJson();*/ $teachers = \App\RegistryStudent::Join('users', function ($join) { $join->on('users.id', '=', 'registry_students.id_student'); })->leftJoin('registry_companies', function ($leftJoin) use($id_company, $id_period) { $leftJoin->on('users.id', '=', 'registry_companies.id_student')->Where('registry_companies.id_company', '=', $id_company)->Where('registry_companies.id_period', '=', $id_period); })->select('registry_students.id as id_registry_student', 'users.id', 'users.first_name', 'users.last_name', 'users.type')->whereNull('registry_companies.id_student')->Where('registry_students.id_period', $id_period)->get()->toJson(); //dd($teachers); //dd(count(json_decode($teachers,true))); } else { // Add code for load teacher whit period $teachers = \App\RegistryCompany::Join('users', 'users.id', '=', 'registry_companies.id_student')->select('registry_companies.id as id_registry_company', 'users.id', 'users.first_name', 'users.last_name', 'users.type')->Where('registry_companies.id_period', $id_period)->Where('registry_companies.id_company', $id_company)->get()->toJson(); } //dd(100); $status = count(json_decode($teachers, true)) > 0 ? true : false; if ($request->ajax()) { return response()->json(['status' => $status, 'data' => $teachers]); } }
public function getRegistryPeriods() { //dd(); $periods = \App\RegistryStudent::Join('periods', 'periods.id', '=', 'registry_students.id_period')->select('registry_students.id as id_registry_student', 'periods.id', 'periods.name', 'periods.start', 'periods.end')->Where('id_student', $this->user->id)->orderBy('periods.end', 'desc')->get(); return $periods; }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy(Request $request, $id) { // $data = $request->all(); $teacherWhitPeriod = \App\RegistryStudent::findOrFail($data['id']); $teacherWhitPeriod->delete(); if ($request->ajax()) { return response()->json(['status' => true, 'data' => 'Was removed successful']); } }