/** * Search in colleges. * * @param string $search * @return Response */ public function search($search) { $return = []; $colleges = College::whereRaw("name LIKE '%" . $search . "%' OR initials LIKE '%" . $search . "%'")->where('deleted_at', null)->take(6)->get(); foreach ($colleges as $id => $college) { $return[] = ["id" => $college->id, "name" => $college->name, "initials" => $college->initials, "city" => $college->city->name, "state" => $college->city->state->uf]; } return response()->json($return); }
/** * Search in College the courses * * @param id * @return Response with courses */ public function getCourses($id) { $colleges = College::find($id)->courses; $courses = []; foreach ($colleges as $id => $college) { $courses[] = ["id" => $college->id, "name" => $college->name]; } return response()->json($courses); }