public function run() { DB::table('phones')->delete(); $collection = [['company_id' => 1, 'phone' => '9016824064', 'type' => 'work'], ['company_id' => 6, 'phone' => '9017592332', 'type' => 'work'], ['user_id' => 1, 'phone' => '9012870209', 'type' => 'mobile']]; foreach ($collection as $record) { Phone::create($record); } }
public function update($id) { // save updated $record = $this->records->find($id); if (!$record) { Phone::create(Input::all()); return $this->respond($record); } $record->fill(Input::all())->save(); return $this->respond($record); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Phone::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'employee_id' => $this->employee_id]); $query->andFilterWhere(['like', 'number', $this->number]); return $dataProvider; }
/** * Execute the job. * * @return void */ public function handle() { $phones = array_map('self::cleanPhone', $this->offer->phones); foreach ($phones as $phone) { $phoneEntry = null; try { $phoneEntry = Phone::firstOrCreate(['id' => self::validatePhone($phone)]); } catch (InvalidPhoneFormatException $e) { $this->offer->invalidPhones()->firstOrCreate(['phone' => $e->getPhone()]); $this->release(); } if ($phoneEntry instanceof Phone) { try { $this->offer->phones()->attach($phoneEntry); $this->dispatch((new UpdatePhoneOfferCount($phoneEntry))->onQueue('update_phone_offer_count')); } catch (QueryException $e) { if (23000 !== intval($e->getCode())) { throw $e; } } } } }
/** * @return \yii\db\ActiveQuery */ public function getPhones() { return $this->hasMany(Phone::className(), ['subscriber_id' => 'id']); }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { $phone = \App\Models\Phone::findOrFail($id); $phone->delete(); return redirect(route('phone.index')); }
public function phoneUpdate(UpdatePhoneRequest $request) { if ($request->ajax()) { $phone = Phone::find($request->input('id')); $phone->update($request->only(['number'])); return response()->json(['msg' => 'Номер телефона обновлен.']); } return redirect()->back() - with('msg', 'У вас браузере не включен javascript. Включите и обновите страницу.'); }
function phone($id) { return view('phone')->with(['phone' => Phone::findOrFail($id)]); }
/** * @return \yii\db\ActiveQuery */ public function getPhones() { return $this->hasMany(Phone::className(), ['employee_id' => 'id']); }
/** * Finds the Phone model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Phone the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Phone::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function countByPhone($phone) { /** @var Phone $phone */ $phone = Phone::findOrFail($phone); return response()->json(['count' => $phone->offers()->count()], 200, [], JSON_UNESCAPED_UNICODE); }
protected function findModelPhones($id) { if (($model = Phone::find()->where(['subscriber_id' => $id])) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }