/** * Not sure if I'm still using this * @param Request $request */ public function insertOrUpdateDateFormat(Request $request) { $new_format = $request->get('new_format'); $preference = Preference::firstOrNew(['type' => 'date_format', 'user_id' => Auth::user()->id]); $preference->value = $new_format; $preference->user()->associate(Auth::user()); $preference->save(); }
public function pref($key, $value = null, $type = 'string') { if (isset($value)) { $this->preferences()->updateOrCreate(['key' => $key], ['value' => $this->cast($value, $type), 'type' => $type]); return $value; } $default = Preference::getDefault($this, $key); return ($pref = $this->preferences()->forKey($key)->first()) ? $pref->value() : $default->value(); }
public function clientHome() { $client = User::find(Auth::user()->id); $clientes = Preference::where('idUser', '=', Auth::user()->id)->get(); $clientPreferences = []; foreach ($clientes as $cliente) { $preferencias = Event::where(['category_id' => $cliente->idCategories, "cancelled" => "0"])->get(); // puede haber varios eventos del mismo tipo foreach ($preferencias as $preference) { array_push($clientPreferences, $preference); } } return view('internal.client.home', compact('clientPreferences', 'client')); }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(UpdateClientRequest $request) { $id = Auth::user()->id; $obj = User::findOrFail($id); $input = $request->all(); $obj->name = $input['name']; $obj->lastname = $input['lastname']; $obj->address = $input['address']; $obj->phone = $input['phone']; $obj->email = $input['email']; $obj->di_type = $input['di_type']; $obj->di = $input['di']; $obj->save(); Preference::where('idUser', '=', $obj->id)->delete(); // rip tabla preferences $values = array_values($input); $i = 8; while (!empty($values[$i])) { $preference = new Preference(); $preference->idUser = $obj->id; $preference->idCategories = $values[$i]; $preference->save(); $i = $i + 1; } Session::flash('message', 'Información de perfil actualizada!'); Session::flash('alert-class', 'alert-success'); return redirect('client'); }