本文整理汇总了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']]);
}
}
示例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);
}
示例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()];
}
示例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);
}
示例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}' 添加成功!");
}