public function postAdd(Request $request) { try { $Input = $request->all(); $delAttr = AttributeWeight::where('user_id', Auth::user()->id)->get(); foreach ($delAttr as $value) { $value->delete(); } foreach ($Input as $key => $value) { if ($key == '_token') { continue; } $attrWt = new AttributeWeight(); $attrWt->user_id = Auth::user()->id; $attrWt->key = $key; $attrWt->value = $value; $attrWt->save(); } return 'Success'; } catch (Exception $e) { $message = 'Priority Setting Error'; $msg_type = 'danger'; return response()->json(['error' => $e->getMessage()], 422); } }
public function getProducts(Request $request) { $attrWt = AttributeWeight::where('user_id', Auth::user()->id)->get(); if (count($attrWt)) { $firstTimeLogin = "******"; } else { $firstTimeLogin = "******"; } $page = 1; if ($request->has('page')) { $page = $request->input('page'); } $products = new Product(); $productArray = $products->recommend($page); return view('dashboard')->with(['products' => $productArray[0], 'paginate' => $productArray[1], 'firstTimeLogin' => $firstTimeLogin]); }
private function get_attribute_weight_value($key) { $val = AttributeWeight::where('user_id', $this->id)->where('key', $key)->get(); if (count($val)) { return $val->first()->value; } else { return null; } }