本文整理匯總了PHP中app\Category::whereId方法的典型用法代碼示例。如果您正苦於以下問題:PHP Category::whereId方法的具體用法?PHP Category::whereId怎麽用?PHP Category::whereId使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類app\Category
的用法示例。
在下文中一共展示了Category::whereId方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testUpdateCategory
/**
* Category Update test
*
* @return void
*/
public function testUpdateCategory()
{
$category = Category::first();
$toUpdate = ['name' => $this->faker->word . '777'];
$endpoint = $this->getEndpointWithToken($this->endpoint . '/' . $category->id);
$this->call('PATCH', $endpoint, $toUpdate);
//fetch inserted category
$updated_category = Category::whereId($category->id)->first();
$this->assertEquals($toUpdate['name'], $updated_category->name);
}
示例2: edit
public function edit($id)
{
$Category = Category::whereId($id)->firstOrFail();
$levelOnes = Category::all()->where('status', 1)->where('parent_id', null);
return view('admin.category.edit', compact('Category', 'levelOnes'));
}
示例3: destroy
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return Response
*/
public function destroy($id)
{
$category = Category::whereId($id)->firstOrFail();
$name = $category->name;
$category->delete();
return redirect()->route('categories.index')->with('status', 'The category ' . $name . ' has been deleted!');
}
示例4: delete
/**
* Delete category
*
* @param $id
*/
public function delete($id)
{
Category::whereId($id)->delete();
}
示例5: setTitleAttribute
public function setTitleAttribute($value)
{
$autoCategories = ['transport', 'cars', 'motorcycles'];
$realtyCategories = ['apartment', 'houses', 'land', 'commercial_realty'];
$request = Request::all();
$categorySlug = Category::whereId($request['category_id'])->first()->slug;
if (in_array($categorySlug, $autoCategories)) {
$autoModel = AutoModel::whereId(Request::input('model'))->first();
$value = sprintf('%s %s, %d', $autoModel->parent->title, $autoModel->title, $request['year']);
}
if (in_array($categorySlug, $realtyCategories)) {
switch ($categorySlug) {
case 'apartment':
$value = sprintf("%s %d-к квартиру, %s м², %d/%d эт.", $request['type_of_ad'], $request['num_of_rooms'], $request['square'], $request['floor'], $request['num_of_floors']);
break;
case 'houses':
$value = sprintf("%s дом, %s м²", $request['type_of_ad'], $request['square']);
break;
case 'land':
$value = sprintf("%s участок, %s сот.", $request['type_of_ad'], $request['square'] / 100);
break;
case 'commercial_realty':
$value = sprintf("%s помещение, %s м²", $request['type_of_ad'], $request['square']);
break;
}
}
$this->attributes['title'] = $value;
}