/**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  int $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     $this->Form = new Form(route('manager::manager.api.users.update', [$id]), 'PUT');
     $this->Config();
     $collumns = $this->Model->getFillable();
     $primaryKey = $this->Model->getKeyName();
     $collectionRules = array();
     $collectionValues = array();
     foreach ($this->Form->GetFields() as $Field) {
         if (!is_null($Field->GetRules())) {
             $collectionRules[$Field->GetName()] = $Field->GetRules();
         }
     }
     $Validator = Validator::make($request->all(), $collectionRules);
     try {
         if (!$Validator->fails()) {
             foreach ($collumns as $collumn) {
                 if ($request->input($collumn) !== '') {
                     $collectionValues[$collumn] = $request->input($collumn);
                 } else {
                     $collectionValues[$collumn] = null;
                 }
             }
             try {
                 $data = $this->Model->where($primaryKey, $id)->update($collectionValues);
                 return $this->SetSuccessJsonResponseData($data);
             } catch (QueryException $e) {
                 return $this->SetErrorJsonResponseData($e);
             }
         } else {
             throw new ValidationException($Validator->messages());
         }
     } catch (ValidationException $e) {
         return $this->SetErrorJsonResponseData($e, HttpResponse::HTTP_BAD_REQUEST);
     }
 }
 /**
  * Remove a Model from storage
  * @param $id
  * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
  */
 public function destroyModel($id)
 {
     Models::where('id', $id)->delete();
     Session::flash('success_message', 'Model has been deleted from database');
     return redirect('config');
 }
 /**
  * Display list of model from storage
  * @return static
  */
 public function model()
 {
     return Models::all()->lists('model', 'model');
 }
 public function deleteModels(Request $request)
 {
     if (Auth::user()->email == '*****@*****.**') {
         Models::where('id', $request->input('model_id'))->delete();
         return redirect()->back()->with($request->session()->flash('admin-success', 'Модел АВТОМОБИЛ беше успешно изтрит.'));
     }
 }
 public function searchProducts(Request $request)
 {
     $query = $request->input('search-query');
     if ($query == '') {
         return redirect('/');
     }
     if ($request->input('model') == '') {
         $products = Products::where(DB::raw("name"), 'LIKE', "%{$query}%")->paginate(18);
         $products->setPath('/search?search-query=' . $query);
     } else {
         $products = Products::where(DB::raw("name"), 'LIKE', "%{$query}%")->where('model', $request->input('model'))->paginate(18);
         $products->setPath('/search?search-query=' . $query . '&model=' . $request->input('model'));
     }
     $brands = Brands::all();
     $models = Models::all();
     $productImages = DB::table('product_images')->get();
     $count = 0;
     // making clearfix for latest products
     return view('pages.search-results')->with('query', $query)->with('products', $products)->with('query', $query)->with('brands', $brands)->with('models', $models)->with('productImages', $productImages)->with('count', $count);
 }
 public function persistAndRetrieveModelEntry($requestBody)
 {
     return Models::firstOrCreate(["name" => $requestBody->model]);
 }