public function update(CustomerRequest $request, $id) { $inputs = $request->input(); $file = $request->file('picture'); $destinationPath = base_path() . '/public/image/customer/'; if ($request->hasFile('picture')) { $name = time() . $file->getClientOriginalName(); $file->move($destinationPath, $name); $inputs['picture'] = $name; } $inputs['updated_by'] = Auth::user()->id; $inputs['updated_at'] = time(); // $customer=Customer::findOrFail($id); unset($inputs['_method']); unset($inputs['_token']); Customer::where(['id' => $id])->update($inputs); Session::flash('flash_message', 'Customer updated successfully'); return redirect('customers'); }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update(CustomerRequest $request, $id) { $customers = Customer::find($id); $customers->name = Input::get('name'); $customers->email = Input::get('email'); $customers->phone_number = Input::get('phone_number'); $customers->address = Input::get('address'); $customers->city = Input::get('city'); $customers->state = Input::get('state'); $customers->zip = Input::get('zip'); $customers->company_name = Input::get('company_name'); $customers->account = Input::get('account'); $customers->save(); // process avatar $image = $request->file('avatar'); if (!empty($image)) { $avatarName = 'cus' . $id . '.' . $request->file('avatar')->getClientOriginalExtension(); $request->file('avatar')->move(base_path() . '/public/images/customers/', $avatarName); $img = Image::make(base_path() . '/public/images/customers/' . $avatarName); $img->resize(100, null, function ($constraint) { $constraint->aspectRatio(); }); $img->save(); $customerAvatar = Customer::find($id); $customerAvatar->avatar = $avatarName; $customerAvatar->save(); } // redirect Session::flash('message', 'You have successfully updated customer'); return Redirect::to('customers'); }