public function run() { $bodyTypes = [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]; ModelRef::where('vehicle_type_id', 2)->chunk(100, function ($models) use($bodyTypes) { $models->each(function ($model) use($bodyTypes) { $model->bodyTypes()->attach($bodyTypes); }); }); }
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); }