public function importExcel() { $fileInfo = $this->uploadFile(request()->file('file'), 'import'); $pathToFile = $fileInfo['path'] . '/' . $fileInfo['name']; Excel::selectSheets('Sheet1')->load($pathToFile, function ($reader) { $rows = $reader->get(); foreach ($rows as $key => $value) { // b1: find order with unit, order_name, order_phone $query = DB::table('orders')->join('units', 'orders.unit_id', '=', 'units.id')->join('phones', 'orders.id', '=', 'phones.order_id')->join('purposes', 'orders.purpose_id', '=', 'purposes.id')->where('phones.number', $value['so_dien_thoai'])->where('units.symbol', $value['don_vi_yc'])->where('orders.order_name', 'like', '%' . $value['ho_ten_doi_tuong'] . '%')->where('purposes.group', 'monitor')->select('phones.id'); $order = $query->first(); if (isset($order)) { // up date status phone $phone = Phone::find($order->id); if ($phone->status != 'success') { $phone->status = 'success'; $phone->save(); } $input = $this->excelForShip($value, $order->id); $newShip = new ShipRepository(new Ship()); $newShip->create($input); } } }); return redirect()->back(); }
public function update($id, array $input, $fileName = '') { $ship = $this->findById($id); // update phone status if ($input['news'] == null) { $phone = $ship->phone; $phone->status = 'warning'; $phone->save(); $phone = Phone::find($input['phone']); $phone->status = 'success'; $phone->save(); } // update ship $ship->date_submit = Carbon::createFromFormat('d/m/Y', $input['created_at']); $ship->phone_id = $input['phone']; $ship->number_cv_pa71 = $input['number_cv_pa71']; $ship->news = $input['news']; $ship->page_news = $input['page_news']; $ship->page_list = $input['page_list']; $ship->page_xmctb = $input['page_xmctb']; $ship->page_imei = $input['page_imei']; $ship->receive_name = $input['receive_name']; $ship->user_id = $input['user_name']; if ($fileName != '') { $ship->file_name = $fileName; } $ship->save(); // syn network table if (isset($input['network'])) { $ship->networks()->sync($input['network']); } return $ship; }
public function changeContactInfo(Request $request) { if ($request->type == 'contact') { $item = Contact::find($request->entity); if ($request->name == 'first_name') { $item->first_name = $request->value; } elseif ($request->name == 'last_name') { $item->last_name = $request->value; } elseif ($request->name == 'email') { $item->email = $request->value; } elseif ($request->name == 'title') { $item->title = $request->value; } else { } $item->save(); } elseif ($request->type == 'address') { $item = Address::find($request->entity); $item->full_string = $request->value; $item->save(); return $request->all(); } elseif ($request->type == 'phone') { $item = Phone::find($request->entity); if ($request->name == 'type') { $item->type = $request->value; } elseif ($request->name == 'number') { $item->number = $request->value; } elseif ($request->name == 'from') { $item->available_from = $request->value; } elseif ($request->name == 'to') { $item->available_to = $request->value; } else { } $item->save(); return $request->all(); } else { } }
public function testMorphHas() { $user = User::find(1); $photo = $user->photo; $this->assertInstanceOf('App\\Photo', $photo); $phone = Phone::find(1); $photos = $phone->photos; $this->assertSame(FALSE, $photos->isEmpty()); }
/** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { // $phone = Phone::find($id); return view('phone.edit')->with('phone', $phone); }
public function index() { dd(Phone::find(4)->user); }
public function updateStatus(Request $request, $phoneId) { $phone = Phone::find($phoneId); $order = $this->order->findById($phone->order_id); $order->comment = $request->get('comment'); $order->save(); $phone->status = $request->get('status'); $phone->save(); return redirect()->back(); }
public function phone($id) { Phone::find($id)->delete(); return back(); }
public function testDelete() { // test delete() $phone = Phone::find(1); $this->assertNotNull($phone); $phone = Phone::find(1); $phone->delete(); $phone = Phone::find(1); $this->assertNull($phone); // test delete() with query builder // Post is soft delete model $posts = Post::where('id', '<', 3)->get(); $this->assertFalse($posts->isEmpty()); Post::where('id', '<', 3)->delete(); $posts = Post::where('id', '<', 3)->get(); $this->assertTrue($posts->isEmpty()); // test destroy() $phone = Phone::find(2); $this->assertNotNull($phone); Phone::destroy(2); $phone = Phone::find(2); $this->assertNull($phone); $photos = Photo::all(); $this->assertFalse($photos->isEmpty()); Photo::destroy([1, 2, 3]); $photos = Photo::all(); $this->assertTrue($photos->isEmpty()); // test destopy with non-existing primary key // expect no exception Photo::destroy([1, 2, 3]); $photos = Photo::all(); $this->assertTrue($photos->isEmpty()); }