/** * Execute the console command. * * @return mixed */ public function fire() { dd('test'); $vehicleTypes = VehicleTypeRef::all(); Category::where('id', '>', 58)->whereNull('parent_id')->get()->each(function ($category) use($vehicleTypes) { $category->categories->each(function ($subCategory) use($category, $vehicleTypes) { // $vehicleTypes->each(function ($vehicleType) use($category, $subCategory) { // if ($subCategory->title != "{$vehicleType->ru} {$category->name}") { $subCategory->description = "Все об {$subCategory->title}"; // } else { // different description // } // }); if ($subCategory->save()) { $this->line($subCategory->title); $this->line($subCategory->description . PHP_EOL); } }); }); $marks = MarkRef::all(); Category::where('id', '>', 58)->whereNotNull('parent_id')->get()->each(function ($category) use($vehicleTypes, $marks) { $marks->each(function ($mark) use($category, $vehicleTypes) { $vehicleTypes->each(function ($vehicleType) use($category, $mark) { if ($category->title == "{$vehicleType->ru} {$mark->name}") { $newTitle = $this->morph($vehicleType) . $mark->name; $this->line("{$category->title} to {$newTitle}"); // $category->title = $newTitle; // $category->save(); } }); }); }); }
/** * Display a listing of the resource. * GET /admin/users * * @return Response */ public function index() { $users = User::withTrashed(); foreach (Input::all() as $key => $input) { if (in_array($key, ['vehicle_type', 'mark', 'model', 'body_type'])) { $users->whereHas('cars', function ($q) use($key, $input) { $q->where($key, $input); }); } elseif ($key == 'city') { $users->where($key, $input); } } $users = $users->with('cityRef')->paginate(); return View::make('admin.users.index', ['title' => 'Пользователи', 'columns' => ['ID', 'Аватар', 'Имя', 'Почта', 'Номер телефона', 'Город', 'Возраст', 'Сообщений', 'Удален в', '', ''], 'data' => $users->transform(function ($user) { return ['id' => $user->id, 'img' => "<img src='{$user->img_small}'>", 'name' => link_to_action('AdminUsersController@show', $user->name, [$user->id]), 'email' => $user->email, 'phone' => $this->returnIfPresent($user, 'phone', 'number'), 'city' => $this->returnIfPresent($user, 'cityRef', 'ru'), 'age' => $user->birthday, 'messages' => $user->messages()->count(), 'deleted' => $user->deleted_at, 'edit' => link_to_action('AdminUsersController@edit', 'ред', [$user->id]), 'delete' => link_to_action('AdminUsersController@edit', 'удал', [$user->id])]; }), 'links' => $users->links(), 'actions' => [link_to('#modal1', 'Разослать', ['class' => 'btn btn-primary btn-md margin']), link_to('#modal1', 'Опубликовать в ленту', ['class' => 'btn btn-primary btn-md margin']), link_to('#model1', 'Удалить выбранное', ['class' => 'btn btn-primary btn-md margin'])], 'filters' => [['param' => 'city', 'name' => 'Город', 'data' => CityRef::all()->transform(function ($city) { return ['id' => $city->id, 'name' => $city->ru]; }), 'active' => Input::get('city')], ['param' => 'vehicle_type', 'name' => 'Тип Авто', 'data' => VehicleTypeRef::all()->transform(function ($v) { return ['id' => $v->id, 'name' => $v->ru]; }), 'active' => Input::has('vehicle_type')], ['param' => 'mark', 'name' => 'Марка', 'data' => MarkRef::all()->transform(function ($m) { return ['id' => $m->id, 'name' => $m->name]; }), 'active' => Input::has('mark')], ['param' => 'model', 'name' => 'Модель', 'data' => ModelRef::all()->transform(function ($m) { return ['id' => $m->id, 'name' => $m->name]; }), 'active' => Input::Has('model')], ['param' => 'body_type', 'name' => 'Кузов', 'data' => BodyTypeRef::all()->transform(function ($b) { return ['id' => $b->id, 'name' => $b->ru]; }), 'active' => Input::has('body_type')]]]); }
public function create() { return View::make('admin.marks.create', ['vehicles' => VehicleTypeRef::all()->transform(function ($vehicle) { return ['exists' => false, 'id' => $vehicle->id, 'ru' => $vehicle->ru]; }), 'title' => 'Создать марку']); }
/** * Execute the console command. * * @return mixed */ public function fire() { $locales = ['ru', 'az']; if ($this->option('with_categories')) { $this->info("Compile categories is on"); MarkRef::with('models')->get()->each(function ($mark) { $this->line("Looking for {$mark->name}"); $category = Generator::findOrCreate($mark->name); if ($category) { Generator::findOrCreate("Все о {$mark->name}", '', $category->id); $mark->models->each(function ($model) use($mark, $category) { $this->line("Looking on {$model->name}"); Generator::findOrCreate($mark->name . ' ' . $model->name, 'Все что касается этой модели.', $category->id); }); } }); } $configDate = Carbon::now()->toDateTimeString(); $oldConfigDate = Config::get('database.refs-version'); foreach ($locales as $locale) { $this->info('Compiling models'); $tempDate = Carbon::now(); $chunk = 200; $this->line("Batch {$chunk}"); ModelRef::with('bodyTypes')->chunk($chunk, function ($models) use($oldConfigDate, $configDate, $locale) { Cache::forget("models-{$oldConfigDate}-{$locale}-part{$models->last()->id}"); Cache::forever("models-{$configDate}-{$locale}-part{$models->last()->id}", $models->toArray()); $this->line("End of chunk {$models->last()->id}"); }); Cache::forget("models-{$oldConfigDate}-{$locale}"); Cache::forever("models-{$configDate}-{$locale}", ModelRef::all()); $this->info("Finished compiling models. {$tempDate->diffInSeconds(Carbon::now(), true)} seconds"); $this->info('Compiling marks'); $tempDate = Carbon::now(); Cache::forget("marks-{$oldConfigDate}-{$locale}"); Cache::forever("marks-{$configDate}-{$locale}", MarkRef::with('vehicleTypes')->get()->toArray()); $this->info("Finished compiling marks.{$tempDate->diffInSeconds(Carbon::now(), true)} seconds"); $this->info('Compiling vehicle types'); $tempDate = Carbon::now(); Cache::forget("vehicle-types-{$oldConfigDate}-{$locale}"); Cache::forever("vehicle-types-{$configDate}-{$locale}", VehicleTypeRef::all()->transform(function ($type) { return ['id' => $type->id, 'name' => $type->ru]; })->toArray()); $this->info("Finished compiling vehicle types. {$tempDate->diffInSeconds(Carbon::now(), true)} seconds"); $this->line('Compiling cities'); $tempDate = Carbon::now(); Cache::forget("cities-{$oldConfigDate}-{$locale}"); Cache::forever("cities-{$configDate}-{$locale}", CityRef::all()->transform(function ($city) use($locale) { return ['name' => $city->{$locale}, 'id' => $city->id]; })->toArray()); $this->info("Finished compiling cities. {$tempDate->diffInSeconds(Carbon::now(), true)} seconds"); $this->info('Compiling body types'); $tempDate = Carbon::now(); Cache::forget("body-types-{$oldConfigDate}-{$locale}"); Cache::forever("body-types-{$configDate}-{$locale}", BodyTypeRef::all()->transform(function ($type) use($locale) { return ['id' => $type->id, 'name' => $type->{$locale}]; })->toArray()); $this->info("Finishing compiling body types. {$tempDate->diffInSeconds(Carbon::now(), true)} seconds"); } Cache::forever('database.refs-version', $configDate); }
public function all() { $this->locale = in_array(Request::header('Locale'), $this->avaibleLocales) ? Request::header('Locale') : $this->avaibleLocales[0]; $date = Input::has('date') ? Input::get('date') : null; if (is_null($date)) { $cities = CityRef::all(); $vehicles = VehicleTypeRef::all(); $bodyTypes = BodyTypeRef::all(); $marks = MarkRef::all(); $models = ModelRef::all(); } else { $cities = CityRef::where('updated_at', '>=', $date)->get(); $vehicles = VehicleTypeRef::where('updated_at', '>=', $date)->get(); $marks = MarkRef::where('updated_at', '>=', $date)->get(); $bodyTypes = BodyTypeRef::where('updated_at', '>=', $date)->get(); $models = ModelRef::where('updated_at', '>=', $date)->get(); } $response['vehicle-types'] = $this->transformVehicles($vehicles); $response['body-types'] = $this->transformBodyTypes($bodyTypes); $response['cities'] = $this->transformCities($cities); $response['models'] = $models; $response['marks'] = $marks; $response['date'] = Carbon::now()->toDateTimeString(); return $this->respond($response); }
public function create() { return View::make('admin.models.create', ['vehicles' => VehicleTypeRef::all()->transform(function ($v) { return ['id' => $v->id, 'ru' => $v->ru, 'exists' => false]; }), 'marks' => MarkRef::all()]); }