Example #1
0
 public static function addProduct($i)
 {
     $item_name = ['Jacket', 'Hoodie', 'Kaos', 'Kemeja', 'Short Pants', 'Long Pants', 'Topi', 'Tas'];
     $color = ['Red', 'Blue', 'Green', 'Tosca', 'Tourquish', 'Orange', 'Lavender', 'Purple', 'Deep Purple', 'Pink', 'White', 'Black'];
     $style = ['Arrival', 'Retro', 'Minimalist', 'Simple', 'Unique', 'Fresh', 'Vintage', 'Stylish', 'Cool', 'Calm'];
     $kataunik = ['Komandan', 'Kopral', 'Sersan', 'Homeless', 'Rocker', 'Freaker', 'Temporary', 'Hancur', 'Baper', 'Kuper', 'Gawl'];
     $deskripsi = ['cocok untuk bepergian ke mana-mana', 'cocok bagi anak muda yang mencari jati diri', 'dipakai untuk segala momen', 'mencerahkan penampilanmu'];
     $harga = ['200000', '250000', '300000', '350000', '400000', '450000', '500000'];
     $gambar = ['jacket_distro.jpg', 'hoodie_distro.jpg', 'kaos_distro.jpg', 'kemeja_distro.jpg', 'short_pants_distro.jpg', 'long_pants_distro.png', 'topi_distro.jpg', 'tas_distro.jpg'];
     $ukuran = ['XS', 'S', 'M', 'L', 'XL', 'XXL'];
     $product = new Product();
     $product->brand_id = Brand::max('id');
     $product->category_id = $i;
     $product->name = $item_name[$i - 1] . ' ' . $color[rand(1, count($color) - 1)] . ' ' . $style[rand(1, count($style) - 1)] . ' ' . $kataunik[rand(1, count($kataunik) - 1)];
     $product->description = $item_name[$i - 1] . ' ' . $color[rand(1, count($color) - 1)] . ' ' . $style[rand(1, count($style) - 1)] . ' ' . $kataunik[rand(1, count($kataunik) - 1)] . ' ' . $deskripsi[rand(1, count($deskripsi) - 1)];
     $product->total_stock = rand(6, 10);
     $product->price_origin = $harga[rand(1, count($harga) - 1)];
     $product->price_discount = $harga[rand(1, count($harga) - 1)];
     $product->discount = '20';
     $product->available_from = '2015-07-01';
     $product->available_to = '2015-07-15';
     $product->save();
     $photo = new Photo();
     $photo->product_id = Product::max('id');
     $photo->caption = $item_name[$i - 1];
     $photo->photo_name = $gambar[$i - 1];
     $photo->photo_url = 'assets/sandbox/' . $gambar[$i - 1];
     $photo->save();
     $size = new Size();
     $size->product_id = Product::max('id');
     $size->name = $ukuran[rand(1, count($ukuran) - 1)];
     $size->stock = rand(1, 3);
     $size->save();
 }
Example #2
0
 public function search(Request $request)
 {
     $data = Brand::with('products')->where('name', 'LIKE', '%' . $request->input('q') . '%')->get();
     if ($data->count() > 0) {
         return Response::json(['error' => false, 'count' => $data->count(), 'data' => ['brand' => $data, 'base_url' => url()]]);
     } else {
         return Response::json(['error' => true, 'message' => 'No data brand found']);
     }
 }