当前位置: 首页>>代码示例>>PHP>>正文


PHP Category::whereName方法代码示例

本文整理汇总了PHP中app\Category::whereName方法的典型用法代码示例。如果您正苦于以下问题:PHP Category::whereName方法的具体用法?PHP Category::whereName怎么用?PHP Category::whereName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app\Category的用法示例。


在下文中一共展示了Category::whereName方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: saveFromList

 /**
  * 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']]);
     }
 }
开发者ID:slawisha,项目名称:computer-shop,代码行数:12,代码来源:ProductRepository.php

示例2: testCreateCategory

 /**
  * 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);
 }
开发者ID:hootlex,项目名称:apodeiksi,代码行数:14,代码来源:CategoriesApiTest.php

示例3: getArticles

 /**
  * 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()];
 }
开发者ID:NewsRepost,项目名称:Fetcher,代码行数:17,代码来源:CategoryController.php

示例4: browseCategory

 /**
  * 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);
 }
开发者ID:hootlex,项目名称:apodeiksi,代码行数:17,代码来源:AdminPagesController.php

示例5: postCreate

 /**
  * 创建分类 
  *
  * @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}' 添加成功!");
 }
开发者ID:jacobcyl,项目名称:writor,代码行数:31,代码来源:CategoryController.php


注:本文中的app\Category::whereName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。