public function index(Request $request) { $steps = Step::pluck('name', 'id')->toArray(); $periods = Period::pluck('name', 'id')->toArray(); $current_period = Period::current()->first(); $specialties = Specialty::pluck('name', 'id')->toArray(); $countries = Country::pluck('name', 'id')->toArray(); $cities = City::pluck('name', 'id')->toArray(); $type = Type::pluck('title', 'id')->toArray(); // $filter_period = null; if (request('period_id')) { $filter_period = request('period_id'); } if ($current_period) { $filter_period = $current_period->id; } if (!$current_period && !request('period_id')) { $filter_period = Period::orderBy('id', 'desc')->first()->id; } $registration_count = Registration::orderBy('id', 'desc'); $registration_gender = Registration::groupBy('gender'); $registration_type = Registration::groupBy('registration_type_id'); $registration_specialty = Registration::groupBy('academystructure_specialty_id'); $registration_country = Registration::groupBy('contact_country_id'); $registration_city = Registration::groupBy('contact_city_id'); $registration_step = null; if ($filter_period != null) { $registration_count->where('registration_period_id', $filter_period); $registration_gender->where('registration_period_id', $filter_period); $registration_type->where('registration_period_id', $filter_period); $registration_specialty->where('registration_period_id', $filter_period); $registration_country->where('registration_period_id', $filter_period); $registration_city->where('registration_period_id', $filter_period); } if (request('step_id')) { $registration_count->where('registration_step_id', request('step_id')); $registration_gender->where('registration_step_id', request('step_id')); $registration_type->where('registration_step_id', request('step_id')); $registration_specialty->where('registration_step_id', request('step_id')); $registration_country->where('registration_step_id', request('step_id')); $registration_city->where('registration_step_id', request('step_id')); } else { $registration_step = Registration::groupBy('registration_step_id'); if ($filter_period != null) { $registration_step->where('registration_period_id', $filter_period); } $registration_step = $registration_step->select('registration_step_id as step', DB::raw('count(*) as total'))->orderBy('total', 'desc')->get()->toArray(); } $registration_count = $registration_count->count(); $registration_gender = $registration_gender->select('gender', DB::raw('count(*) as total'))->orderBy('total', 'desc')->get()->toArray(); $registration_type = $registration_type->select('registration_type_id', DB::raw('count(*) as total'))->orderBy('total', 'desc')->get()->toArray(); $registration_specialty = $registration_specialty->select('academystructure_specialty_id as specialty', DB::raw('count(*) as total'))->orderBy('total', 'desc')->get()->toArray(); $registration_country = $registration_country->select('contact_country_id as country', DB::raw('count(*) as total'))->orderBy('total', 'desc')->get()->toArray(); $registration_city = $registration_city->select('contact_city_id as city', 'contact_country_id as country', DB::raw('count(*) as total'))->orderBy('total', 'desc')->get()->toArray(); return view('registration::reports.index', compact('steps', 'periods', 'current_period', 'specialties', 'countries', 'type', 'cities', 'registration_gender', 'registration_specialty', 'registration_country', 'registration_step', 'registration_count', 'registration_type', 'registration_city')); }
public function index(Request $request) { $per_page = request('per_page', 20); $students = $this->prepQuery($request->all()); $students = $students->paginate($per_page); $students->appends($request->except('page')); $year_term = Year::join('academystructure_terms', 'academystructure_years.id', '=', 'academystructure_terms.year_id')->select(\DB::raw('CONCAT(academystructure_years.name, "-", academystructure_terms.name) as name, academystructure_terms.id as tid'))->groupBy('academystructure_terms.name', 'academystructure_years.name')->orderBy('academystructure_terms.id')->pluck('name', 'tid')->toArray(); $spec_id = Specialty::pluck('name', 'id')->toArray(); $county = Country::pluck('name', 'id')->toArray(); $city = City::pluck('name', 'id')->toArray(); // return $students->pluck('sps'); return view('students::students.index', compact('students', 'year_term', 'spec_id', 'county', 'city')); }
public function export(Request $request) { Excel::create('registrations', function ($excel) { $excel->sheet('registrations', function ($sheet) { $steps = RegistrationStep::pluck('name', 'id')->toArray(); $specialties = Specialty::pluck('name', 'id')->toArray(); $type = RegistrationType::pluck('title', 'id')->toArray(); $genders = config('registration.genders'); $countries = Country::pluck('name', 'id')->toArray(); $cities = City::pluck('name', 'id')->toArray(); $states = State::pluck('name', 'id')->toArray(); $years = AcademycycleYear::pluck('name', 'id')->toArray(); $registration_periods = RegistrationPeriod::pluck('name', 'id')->toArray(); $registrations = $this->prepQuery(request()->all())->get(); $sheet->loadView('registration::registrations.export', compact('registration_periods', 'registrations', 'steps', 'countries', 'years', 'specialties', 'type', 'genders', 'cities', 'states')); })->download('xlsx'); }); }