/** * Execute the console command. * * @return mixed */ public function fire() { $this->config = $this->getConfig(); $opts = $this->option(); if ($opts['forget']) { if (isset(array_dot($this->config)[$opts['forget']])) { $keys = explode('.', $opts['forget']); array_forget($this->config, $opts['forget']); if (empty($this->config[$keys[0]])) { DB::table('config')->where('name', $keys[0])->delete(); } else { DB::table('config')->where('name', $keys[0])->update(['value' => serialize($this->config[$keys[0]])]); } $this->info($opts['forget'] . ' removed.'); } return $this->showList(); } if ($opts['key'] && $opts['value']) { $value = trim($opts['value']); if (in_array($value, ['true', 'false', '0', '1'])) { $value = filter_var($value, FILTER_VALIDATE_BOOLEAN); } $old_config = $this->config; array_set($this->config, $opts['key'], $value); $keys = explode('.', $opts['key']); if (isset($old_config[$keys[0]])) { //update DB::table('config')->where('name', $keys[0])->update(['value' => serialize($this->config[$keys[0]])]); } else { //insert DB::table('config')->insert(['name' => $keys[0], 'value' => serialize($this->config[$keys[0]])]); } } return $this->showList(); }
/** * @param array $options * @return string */ public function open(array $options = []) { $this->errors = array_get($options, 'errors'); array_forget($options, 'errors'); array_set($options, 'files', true); return parent::open($options); }
public function prepareData($data) { if (isset($data['avatar'])) { if (!in_array($this->data['avatar']->mimeType, $this->images)) { $this->errors->messages = array_add($this->errors->messages, 'avatar', $this->array); } else { $data = $this->moveAvatar($data); $data['available_perfil'] = true; } } else { array_forget($data, 'avatar'); } if (isset($data['ficha1'])) { $data = $this->moveFicha1($data); } else { array_forget($data, 'ficha1'); } if (isset($data['ficha2'])) { $data = $this->moveFicha2($data); } else { array_forget($data, 'ficha2'); } $data['full_name'] = strip_tags($data['full_name']); $data['movil'] = strip_tags($data['movil']); $data['institucion_procedencia'] = strip_tags($data['institucion_procedencia']); $data['estado'] = strip_tags($data['estado']); $data['municipio'] = strip_tags($data['municipio']); $data['domicilio'] = strip_tags($data['domicilio']); return $data; }
protected function prepareData($fill) { if (empty($fill['sites_id'])) { $fill['sites_id'] = app('veer')->siteId; } if (empty($fill['users_id']) && $this->action != 'add') { $fill['users_id'] = \Auth::id(); } foreach (['free', 'close', 'hidden', 'archive', 'delivery_free', 'delivery_hold', 'payment_hold', 'payment_done'] as $key) { $fill[$key] = isset($fill[$key]) ? 1 : 0; } if ($fill['close']) { $fill['close_time'] = now(); } $fill['progress'] = isset($fill['progress']) ? strtr($fill['progress'], ["%" => ""]) : 5; $fill['delivery_plan'] = !empty($fill['delivery_plan']) ? parse_form_date($fill['delivery_plan']) : null; $fill['delivery_real'] = !empty($fill['delivery_real']) ? parse_form_date($fill['delivery_real']) : null; $fill += ['cluster_oid' => null, 'cluster' => null, 'delivery_method_id' => $this->order->delivery_method_id, 'payment_method_id' => $this->order->payment_method_id, 'status_id' => $this->order->status_id, 'userbook_id' => $this->order->userbook_id]; if ($this->order->cluster_oid != $fill['cluster_oid'] || $this->order->cluster != $fill['cluster']) { $existingOrders = \Veer\Models\Order::where('sites_id', '=', $fill['sites_id'])->where('cluster', '=', $fill['cluster'])->where('cluster_oid', '=', $fill['cluster_oid'])->first(); // we cannot update cluster ids if they already exist if (is_object($existingOrders) || empty($fill['cluster_oid'])) { array_forget($fill, ['cluster_oid', 'cluster']); } } if ($this->order->delivery_method_id != $fill['delivery_method_id'] && empty($fill['delivery_method'])) { $fill['delivery_method'] = \Veer\Models\OrderShipping::where('id', '=', $fill['delivery_method_id'])->pluck('name'); } if ($this->order->payment_method_id != $fill['payment_method_id'] && empty($fill['payment_method'])) { $fill['payment_method'] = \Veer\Models\OrderPayment::where('id', '=', $fill['payment_method_id'])->pluck('name'); } return $fill; }
/** * Get all of the data except for a specified array of items. * * @param array $keys * @return array */ public function except($keys) { $keys = is_array($keys) ? $keys : func_get_args(); $results = $this->all(); array_forget($results, $keys); return $results; }
/** * Generates a signature for a packet request response * * @param array $packet * @param int|null $code * @param string|\Exception|null $message * * @return array * */ protected static function signPacket(array $packet, $code = null, $message = null) { $_ex = false; if ($code instanceof \Exception) { $_ex = $code; $code = null; } elseif ($message instanceof \Exception) { $_ex = $message; $message = null; } !$code && ($code = Response::HTTP_OK); $code = $code ?: ($_ex ? $_ex->getCode() : Response::HTTP_OK); $message = $message ?: ($_ex ? $_ex->getMessage() : null); $_startTime = \Request::server('REQUEST_TIME_FLOAT', \Request::server('REQUEST_TIME', $_timestamp = microtime(true))); $_elapsed = $_timestamp - $_startTime; $_id = sha1($_startTime . \Request::server('HTTP_HOST') . \Request::server('REMOTE_ADDR')); // All packets have this $_packet = array_merge($packet, ['error' => false, 'status_code' => $code, 'request' => ['id' => $_id, 'version' => static::PACKET_VERSION, 'signature' => base64_encode(hash_hmac(config('dfe.signature-method'), $_id, $_id, true)), 'verb' => \Request::method(), 'request-uri' => \Request::getRequestUri(), 'start' => date('c', $_startTime), 'elapsed' => (double) number_format($_elapsed, 4)]]); // Update the error entry if there was an error if (!array_get($packet, 'success', false) && !array_get($packet, 'error', false)) { $_packet['error'] = ['code' => $code, 'message' => $message, 'exception' => $_ex ? Json::encode($_ex) : false]; } else { array_forget($_packet, 'error'); } return $_packet; }
/** * Update the specified resource in storage. * * @param UpdateUserRequest $request * * @return bool */ public function update($request) { $inputs = $request->all(); if ($this->user->is_validate && !Hash::check($inputs['current_password'], $this->user->password)) { return false; } if (!$this->user->is_validate && empty($inputs['password'])) { return false; } if (!isset($inputs['phone']) || empty($inputs['phone'])) { $inputs['is_phone'] = false; } if (empty($inputs['password'])) { array_forget($inputs, ['password', 'password_confirm']); } if ($request->hasFile('avatar')) { $this->makeAvatarFor($this->user, $request->file('avatar')); } $this->user->fill($inputs); $this->user->is_validate = 1; event(new UserWillBeUpdated($this->user, $this->user)); $this->user->save(); event(new UserWasUpdated($this->user, $this->user)); return true; }
public function prepareData($data) { if (isset($data['avatar'])) { $data = $this->moveAvatar($data); $data['available_perfil'] = true; } else { array_forget($data, 'avatar'); } if (isset($data['ficha1'])) { $data = $this->moveFicha1($data); } else { array_forget($data, 'ficha1'); } if (isset($data['ficha2'])) { $data = $this->moveFicha2($data); } else { array_forget($data, 'ficha2'); } $data['full_name'] = strip_tags($data['full_name']); $data['movil'] = strip_tags($data['movil']); $data['num_control'] = strip_tags($data['num_control']); $data['estado'] = strip_tags($data['estado']); $data['municipio'] = strip_tags($data['municipio']); $data['domicilio'] = strip_tags($data['domicilio']); return $data; }
/** * Remove element from settings array * * @param $key */ public function forget($key) { if ($this->has($key)) { array_forget($this->data, $key); } $this->persist(); }
/** * Return field groups and field for entry by slug * @return void */ public function addEntryFields($entry) { if ($this->entry_fields) { // Get fields by entry slug $entryKey = str_replace("-", "_", $entry->slug); $entryFields = array_get($this->entry_fields, $entryKey); if ($entryFields) { foreach ($entryFields as $groupKey => $fields) { // Add field to existing group or create new one if ($this->groups->has($groupKey)) { foreach ($fields as $key => $field) { $this->groups[$groupKey]->fields->put($key, $f = new FieldEntity($field)); $this->fields->put($key, $f); } } else { $this->groups->put($groupKey, new FieldGroupEntity($fields)); // Also add the fields to global list foreach ($this->groups[$groupKey]->fields as $newKey => $newField) { $this->fields->put($newKey, $newField); } } } } array_forget($this->data, 'entry_fields'); } }
/** * Get the default transformer class for the model. * * @return string */ protected function getDefaultTransformerNamespace() { $parts = explode('\\', get_class($this)); $class = array_last($parts); array_forget($parts, array_last(array_keys($parts))); return $this->makeTransformer($class, implode('\\', $parts)); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { // $rules = ['c_fname' => 'required|min:2', 'c_lname' => 'required|min:2', 'address' => 'required|min:2', 'city' => 'required|min:2', 'sate' => 'required|min:2', 'phone' => 'required|min:2|unique:merchants', 'email' => 'required|min:5|unique:merchants']; $messages = []; $validator = Validator::make($request->all(), ['c_fname' => 'required|min:2', 'c_lname' => 'required|min:2', 'address' => 'required|min:2', 'city' => 'required|min:2', 'state' => 'required|min:2', 'phone' => 'required|min:2|unique:merchants']); $validator->setAttributeNames(['c_fname' => "Contcat First Name", "c_lname" => "Contact Last Name"]); //$validator->setAttributeName() if ($validator->fails()) { if ($request->ajax()) { return response()->json($validator->messages()); } else { return \Redirect::back()->withErrors($validator)->withInput(); } } $all_request = $request->all(); array_forget($all_request, "_token"); $mid = Merchant::uniqueID() + 1; $merchant = new Merchant(); foreach ($all_request as $key => $value) { $merchant->{$key} = $value; } $merchant->merch_id = $mid; if ($merchant->save()) { return response()->json("record saved successfully"); } return View("merchants.index", ["merchants" => Merchant::all(), "title" => "Merchant"]); }
public function testArrayForget() { $array = array('names' => array('developer' => 'taylor', 'otherDeveloper' => 'dayle')); array_forget($array, 'names.developer'); $this->assertFalse(isset($array['names']['developer'])); $this->assertTrue(isset($array['names']['otherDeveloper'])); }
public function update(Request $request, $id) { array_forget($request, "_token"); $all_request = $request->all(); $task = Task::find($id); foreach ($all_request as $key => $value) { /* * remove all underscore contained * in the edit form field */ $key = preg_replace("/^_/", "", $key); $task->{$key} = $value; } if ($task->update()) { \Session::flash("success_message", "Task Successfully Updated"); } else { \Session::flash("error_message", "Unexpected Error Task could not be updated"); } $tasks = Task::all(); if ($request->ajax()) { response()->json("Task Successfully Updated"); exit; // return \Redirect::back(); } return View("taskmanager.index", ['tasks' => $tasks, 'title' => 'Tasks']); }
/** * Get only designated inputs. * @param array $keys * @param array ['trim' => bool $trim, 'sanitize' => bool $sanitize, 'clean' => bool $clean ] * @return array */ public function except(array $keys, array $param = array()) { $input = $this->getAll(); foreach ($keys as $key) { array_forget($input, $key); } return $this->clean($input, $param); }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { // $input = $request->all(); $validator = Validator::make($input, ['price' => 'required', 'job_type' => 'required', 'job_id' => 'required', 'paper_id' => 'required']); if ($validator->fails()) { return \Redirect::back()->withErrors($validator)->withInput(); } array_forget($request, "_token"); $all_request = $request->all(); $price = Price::find($id); $papers = Paper::all(); $jobs = Job::all(); foreach ($all_request as $key => $value) { $price->{$key} = $value; } $price->update(); $prices = Price::all(); if ($request->ajax()) { if ($prices) { foreach ($prices as $price) { echo "\n <tr>\n <td>{$price->id}</td>\n <td>"; foreach ($papers as $paper) { if ($paper->id == $price->paper_id) { $paperid = $paper->name; echo $paper->name . ", " . $paper->size; } } echo " </td>\n <td>"; foreach ($jobs as $job) { if ($job->id == $price->job_id) { $jobid = $job->name; echo $job->name; } } echo "</td>\n <td>{$price->job_type}</td>\n <td>{$price->price}</td>\n <td><button class='edtPriceLink btn-primary' cpaperid='{$paperid}' cjobtype='{$price->job_type}' cid='{$price->id}' cjobid='{$price->job_id}' cprice='{$price->price}'><span class='glyphicon glyphicon-pencil'></span></button></td>\n <td><button class='btn-danger' data-target='#myModalPaperEdit' data-toggle='modal'><span class='glyphicon glyphicon-trash'></span></button></td>\n </tr>\n "; } } exit; } else { try { if ($price->update()) { \Session::flash("success_message", "New Price Record Updated Successfully"); return \Redirect::back(); } } catch (\Illuminate\Database\QueryException $e) { \Session::flash("error_message", $e->getMessage()); return \Redirect::back(); } catch (\PDOException $e) { \Session::flash("error_message", $e->getMessage()); return \Redirect::back(); } catch (\Exception $e) { \Session::flash("error_message", $e->getMessage()); return \Redirect::back(); } } return View("settings.priceedit", ['jobs' => $jobs, 'papers' => $papers, 'title' => 'Job Setting']); }
/** * Get info from a specify url and cache that using laravel cache manager. * * @param string $url * @param null|array $options * @return mixed */ public function cache($url, array $options = null) { $lifetime = array_get($options, 'lifetime', 60); array_forget($options, 'lifetime'); $self = $this; return $this->cache->remember($url, $lifetime, function () use($self, $url, $options) { return $self->get($url, $options); }); }
public function testArrayForget() { $array = ['child' => ['child' => ['child' => 'no child']]]; $this->assertTrue(isset($array['child']['child']['child']), 'Bad initial array'); array_forget($array, 'child.child.child'); $this->assertTrue(!isset($array['child']['child']['child']), 'Unable to forget array key'); $this->assertTrue(isset($array['child']['child']), 'Bad forget array result'); array_forget($array, 'child.child.child.child'); }
/** * Registers a new telemetry source for aggregation * * @param string $name Provider name * * @return bool True if provider exists and was removed */ public function unregisterProvider($name) { if (in_array($name, $this->providers)) { $this->instances[$name] = null; array_forget($this->instances, $name); return true; } return false; }
public function updateEvenTrashed($model, $data) { array_forget($data, $model::UPDATED_AT); if (!$model->exists) { $model = $model->newQuery()->where('id', $model->id)->withTrashed(); } // dd($model, $data); return $model->update($data) !== false; }
/** * Delete the setting at the given path. * * @param string|null $path * @return array */ public function delete($path = null) { if (!$path) { return $this->set([]); } $settings = $this->all(); array_forget($settings, $path); return $this->apply($settings); }
public function assertArrayFiltered($arr1, $arr2, $ignore_keys = ['created_at', 'updated_at']) { $dot1 = array_dot($arr1); $dot2 = array_dot($arr2); $pattern = sprintf('/(.+\\.)*(%s)/', join($ignore_keys, '|')); array_forget($arr1, preg_grep($pattern, array_keys($dot1))); array_forget($arr2, preg_grep($pattern, array_keys($dot2))); $this->assertEquals($arr1, $arr2); }
public function addRemoveStuff($additional, $removed) { foreach ($additional as $key => $val) { $this->buffer_record[$key] = $val; } foreach ($removed as $key => $val) { array_forget($this->buffer_record, $val); } }
public function testCanCreateTextFieldWithoutBootstrap() { $this->former->framework('Nude'); $input = $this->former->text('foo')->data('foo')->class('bar')->__toString(); $label = $this->matchLabel('Foo'); array_forget($label, 'attributes.class'); $this->assertHTML($label, $input); $this->assertHTML($this->matchField(), $input); }
public function deleteExtend($key) { if (isset($this->{$this->extendColumnName}[$key])) { $tempExtend = $this->{$this->extendColumnName}; array_forget($tempExtend, $key); $this->{$this->extendColumnName} = $tempExtend; unset($tempExtend); } }
/** * @param $namespace * @param null $key */ public function drop($namespace, $key = null) { if (isset($this->registry[$namespace])) { if ($key) { array_forget($this->registry[$namespace], $key); } else { unset($this->registry[$namespace]); } } }
/** * Get added attributes. * * @return array */ public function getAdded() { // add attributes defined by the presenter if (!$this->added) { $added = array_diff_key(array_flip(get_class_methods(static::class)), array_flip(get_class_methods(self::class))); array_forget($added, '__construct'); $this->added = array_flip($added); } return $this->added; }
/** * Set the icon property when the icon is defined in the link attributes. * * @param array $properties * @return array */ protected static function setIconIfDefinedInAttributes(array $properties) { $icon = array_get($properties, 'attributes.icon'); if (!is_null($icon)) { $properties['icon'] = $icon; array_forget($properties, 'attributes.icon'); return $properties; } return $properties; }
/** * Get all of the input except for a specified array of items. * * @param array $keys * * @return array */ public function except($keys) { $keys = is_array($keys) ? $keys : func_get_args(); $results = $this->input(); $results = is_array($results) ? $results : array(); foreach ($keys as $key) { array_forget($results, $key); } return $results; }
/** * Removes keys having empty values from array and trims values. * * @param $array * * @return mixed */ function array_clean(&$array) { foreach ($array as $attribute => $value) { if (empty($value)) { array_forget($array, $attribute); } else { $array[$attribute] = trim($value); } } return $array; }