/**
  * Save products from list
  *
  * @param $products
  */
 public function saveFromList($products)
 {
     $this->cleanTable('products');
     foreach ($products as $product) {
         Product::create(['number' => $product['id'], 'name' => $product['name'], 'manufacturer_id' => Manufacturer::whereName($product['manufacturer'])->first()->id, 'model' => $product['model'], 'category_id' => Category::whereName($product['category'])->first()->id, 'price' => $product['price'], 'processor' => $product['processor'], 'memory' => $product['memory'], 'hdd' => $product['hdd'], 'graphics' => $product['graphics'], 'screen' => $product['screen'], 'optical' => $product['optical']]);
     }
 }
Example #2
0
 /**
  * Category Create test
  *
  * @return void
  */
 public function testCreateCategory()
 {
     $category = ['name' => $this->faker->word . '999'];
     $endpoint = $this->getEndpointWithToken($this->endpoint);
     $this->call('POST', $endpoint, $category);
     //fetch inserted category
     $inserted_category = Category::whereName($category['name'])->first();
     $this->assertInstanceOf('App\\Category', $inserted_category);
 }
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function getArticles($id, $number)
 {
     $category = Category::whereName($id)->first();
     $sources = $category->sources;
     $ids = [];
     foreach ($sources as $source) {
         $ids[] = $source->id;
     }
     $articles = Article::whereIn('source_id', $ids)->orderBy('date', 'DESC')->paginate($number);
     return ['name' => $category->name, 'id' => $category->id, 'image_url' => $category->image_url, 'articles' => $articles->toArray()];
 }
 /**
  * Show all receipts of a specific Category.
  *
  * @param  int  $name
  * @return Response
  */
 public function browseCategory($name)
 {
     $categories = Category::whereName($name)->get();
     $receipts = Collection::make();
     $categories->each(function ($category) use($receipts) {
         $category->receipts->each(function ($receipt) use($receipts) {
             $receipts->push($receipt);
         });
     });
     return view('admin.receipts', compact('receipts'))->with('page_title', $name);
 }
Example #5
0
 /**
  * 创建分类 
  *
  * @param string $value 
  *
  * @return Response
  */
 public function postCreate()
 {
     $rules = array('name' => 'required', 'slug' => 'regex:/^[a-zA-Z 0-9_-]+$/', 'parent_id' => 'integer');
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     // 检测分类名
     if (Category::whereName(Input::get('name'))->count()) {
         return Redirect::back()->withMessage("分类 '" . Input::get('name') . "' 已经存在!")->withColor('danger')->withInput(Input::all());
     }
     //检测别名
     if (Input::get('slug') && Category::whereSlug(Input::get('slug'))->count()) {
         return Redirect::back()->withMessage("分类别名 '" . Input::get('slug') . "' 已经存在!")->withColor('danger')->withInput(Input::all());
     }
     // 创建分类
     $category = new Category();
     $category->name = Input::get('name');
     $category->slug = str_replace(' ', '', snake_case(Input::get('slug')));
     $category->parent = Input::get('parent_id');
     $category->description = Input::get('description');
     $category->save();
     return Redirect::back()->withMessage("分类 '{$category->name}' 添加成功!");
 }