當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。