/**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     //        echo "result:<pre>";
     $result = Product::Where('name', 'like', '%' . Input::get('search') . '%')->get();
     //var_dump($result->toArray());
     return view('search', array('head' => array('title' => 'نتایج جستجو'), 'products' => $result));
 }
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $products_latest = Product::orderBy('created_at', 'DESC')->take(10)->get()->toArray();
     $products_rand1 = Product::orderByRaw("RAND()")->take(10)->get()->toArray();
     $products_rand2 = Product::orderByRaw("RAND()")->take(10)->get()->toArray();
     $products_rand3 = Product::orderByRaw("RAND()")->take(3)->get()->toArray();
     $products_rand5 = Product::orderByRaw("RAND()")->take(5)->get()->toArray();
     $head = array('title' => 'صفحه اصلی');
     $data = array('head' => $head, 'products' => array('latest' => $products_latest, 'rand1' => $products_rand1, 'rand2' => $products_rand2, 'rand3' => $products_rand3, 'rand5' => $products_rand5));
     return view('index', $data);
 }
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show($id)
 {
     $product = Product::find($id)->toArray();
     $additional = null;
     if ($product['category'] == 'laptop') {
         $additional = Laptop::where('id_product', $id)->first()->toArray();
     } elseif ($product['category'] == 'book') {
         $additional = Book::where('id_product', $id)->first()->toArray();
     }
     $product = array_merge($product, $additional);
     $head = array('title' => $product['name']);
     $data = array('head' => $head, 'product' => $product);
     return view('product.show', $data);
 }
 public function postAddProduct()
 {
     $request = Input::all();
     $validator = Validator::make($request, ['name' => 'required|max:255', 'cat' => 'required']);
     if ($validator->fails()) {
         $this->throwValidationException($request, $validator);
         die;
     }
     unset($request['_token']);
     $result = Product::create($request);
     $result = $result->toArray();
     $request['id_product'] = $result['id_product'];
     if ($request['category'] == 'laptop') {
         Laptop::create($request);
     } elseif ($request['category'] == 'laptop') {
         Book::create($request);
     }
     return redirect('/admin/product/add');
 }