/** * Run the database seeds. * * @return void */ public function run() { Model::unguard(); $tr = new TranslateClient('en', 'ar'); $countries = json_decode(File::get(__DIR__ . "/u_countries.json"), true); Country::whereNotNull('id')->delete(); City::whereNotNull('id')->delete(); State::whereNotNull('id')->delete(); foreach ($countries as $country) { $name = $tr->translate($country['name']); //$country['name']; $newCountry = Country::create(['name' => $name, 'iso_3166_2' => $country['iso_3166_2'], 'calling_code' => $country['calling_code']]); } $countries = Country::get(); foreach ($countries as $country) { $new_cities = []; $new_states = []; $states = DB::connection('tests')->table('states')->select('states.*')->join('countries', function ($j) use($country) { $j->on('countries.id', '=', 'states.country_id')->where('countries.sortname', '=', $country->iso_3166_2); })->get(); foreach ($states as $state) { $new_cities[] = ['id' => $state->id, 'name' => $tr->translate($state->name), 'country_id' => $country->id]; $cities = DB::connection('tests')->table('cities')->select('cities.*')->join('states', function ($j) use($state) { $j->on('states.id', '=', 'cities.state_id')->where('states.id', '=', $state->id); })->get(); foreach ($cities as $city) { $new_states[] = ['id' => $city->id, 'name' => $tr->translate($city->name), 'city_id' => $state->id]; } } DB::table('lists_cities')->insert($new_cities); DB::table('lists_states')->insert($new_states); } }
public function deleteBulk(Request $req, City $CityModel, Country $country) { if (!$req->has('table_records')) { return redirect()->route('cities.index'); } $ids = $req->input('table_records'); $CityModel->destroy($ids); return redirect()->route('cities.index', $country->id)->with('success', trans('lists::cities.delete_bulk_success')); }
public function index(City $city, Request $request) { $cities = $city->orderBy('id', 'desc'); if ($request->has('country_id')) { $cities->where('country_id', $request->input('country_id')); } $cities = $cities->get(); return $cities; }
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')); }
/** * Register the service provider. * * @return void */ public function register() { //City City::created(function ($city) { UserLog::create(['operation' => 'create', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Lists_city', 'reference_id' => $city->id]); }); City::updated(function ($city) { UserLog::create(['operation' => 'update', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Lists_city', 'reference_id' => $city->id]); }); City::deleted(function ($city) { UserLog::create(['operation' => 'delete', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Lists_city', 'reference_id' => $city->id]); }); //Country Country::created(function ($country) { UserLog::create(['operation' => 'create', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Lists_country', 'reference_id' => $country->id]); }); Country::updated(function ($country) { UserLog::create(['operation' => 'update', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Lists_country', 'reference_id' => $country->id]); }); Country::deleted(function ($country) { UserLog::create(['operation' => 'delete', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Lists_country', 'reference_id' => $country->id]); }); //Region Region::created(function ($region) { UserLog::create(['operation' => 'create', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Lists_region', 'reference_id' => $region->id]); }); Region::updated(function ($region) { UserLog::create(['operation' => 'update', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Lists_region', 'reference_id' => $region->id]); }); Region::deleted(function ($region) { UserLog::create(['operation' => 'delete', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Lists_region', 'reference_id' => $region->id]); }); //State State::created(function ($state) { UserLog::create(['operation' => 'create', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Lists_state', 'reference_id' => $state->id]); }); State::updated(function ($state) { UserLog::create(['operation' => 'update', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Lists_state', 'reference_id' => $state->id]); }); State::deleted(function ($state) { UserLog::create(['operation' => 'delete', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Lists_state', 'reference_id' => $state->id]); }); }
/** * Run the database seeds. * * @return void */ public function run() { Model::unguard(); $countries = json_decode(File::get(__DIR__ . "/countries.json"), true); $cities = ['OM' => [['name' => 'مسقط', 'states' => [['name' => 'الخوير']]], ['name' => 'البريمي'], ['name' => 'الباطنة شمال'], ['name' => 'الباطنة جنوب'], ['name' => 'الظاهرة'], ['name' => 'الداخلية '], ['name' => 'الشرقية شمال'], ['name' => 'الشرقية جنوب'], ['name' => 'الوسطى'], ['name' => 'ظفار'], ['name' => 'مسندم']]]; $permissions = [['name' => 'اضافة دول', 'slug' => 'create.countries', 'module' => 'lists'], ['name' => 'تعدل دول', 'slug' => 'edit.countries', 'module' => 'lists'], ['name' => 'حذف دول', 'slug' => 'delete.countries', 'module' => 'lists'], ['name' => 'مشاهدة الدولة', 'slug' => 'view.countries', 'module' => 'lists'], ['name' => 'اضافة مدن', 'slug' => 'create.cities', 'module' => 'lists'], ['name' => 'تعدل مدن', 'slug' => 'edit.cities', 'module' => 'lists'], ['name' => 'حذف مدن', 'slug' => 'delete.cities', 'module' => 'lists'], ['name' => 'مشاهدة المدن', 'slug' => 'view.cities', 'module' => 'lists'], ['name' => 'اضافة محافظة', 'slug' => 'create.states', 'module' => 'lists'], ['name' => 'تعدل محافظة', 'slug' => 'edit.states', 'module' => 'lists'], ['name' => 'حذف محافظة', 'slug' => 'delete.states', 'module' => 'lists'], ['name' => 'مشاهدة المحافظات', 'slug' => 'view.states', 'module' => 'lists']]; $slugs = array_map(function ($ar) { return $ar['slug']; }, $permissions); Permission::whereIn('slug', $slugs)->delete(); Country::whereNotNull('id')->delete(); City::whereNotNull('id')->delete(); State::whereNotNull('id')->delete(); $users = User::all(); foreach ($permissions as $permission) { $perm = Permission::create($permission); foreach ($users as $user) { $user->attachPermission($perm); } } $tr = new TranslateClient('en', 'ar'); foreach ($countries as $country) { $name = $country['name']; //$tr->translate($country['name']); $newCountry = Country::create(['name' => $name, 'calling_code' => $country['calling_code']]); if (isset($cities[$country['iso_3166_2']])) { foreach ($cities[$country['iso_3166_2']] as $city) { $newCity = City::create(['name' => $city['name'], 'country_id' => $newCountry->id]); if (isset($city['states'])) { foreach ($city['states'] as $state) { State::create(['name' => $state['name'], 'city_id' => $newCity->id]); } } } } } }
public function create(City $city) { $city->load('country'); return view('lists::states.create', compact('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'); }); }
public function registerEvents() { City::creating(function ($city) { $city->created_by = user() ? user()->id : 1; }); Country::creating(function ($country) { $country->created_by = user() ? user()->id : 1; }); }
public function index(Request $request) { $cities = City::orderBy('name', 'asc')->selectRaw('id as value, name as text')->where('country_id', $request->input('country_id'))->get()->toArray(); return response()->json($cities, 200, [], JSON_NUMERIC_CHECK); }