本文整理汇总了PHP中app\Category::findOrFail方法的典型用法代码示例。如果您正苦于以下问题:PHP Category::findOrFail方法的具体用法?PHP Category::findOrFail怎么用?PHP Category::findOrFail使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Category
的用法示例。
在下文中一共展示了Category::findOrFail方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: update
/**
* Update the specified resource in storage.
*
* @param int $id
* @return Response
*/
public function update($id, Request $request)
{
//$this->validate($request, ['name' => 'required']); // Uncomment and modify if you need to validate any input.
$category = Category::findOrFail($id);
$category->update($request->all());
return redirect('category');
}
示例2: update
/**
* Update the specified resource in storage.
*
* @param int $id
*
* @return Response
*/
public function update($id, Request $request)
{
$category = Category::findOrFail($id);
$category->update($request->all());
Session::flash('flash_message', 'Category updated!');
return redirect('admin/category');
}
示例3: update
/**
* Update the specified resource in storage.
*
* @param int $id
*
* @return Response
*/
public function update(CategoryRequest $request, $id)
{
$category = Category::findOrFail($id);
$category->update($request->all());
\Cache::tags('categories')->flush();
return redirect('admin/categories/index');
}
示例4: show
/**
* Display the products of the specified category.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
$category = Category::findOrFail($id);
$categoryIdNav = $category->id;
$products = $category->products()->latest()->available()->paginate(12);
return view('category.show', compact('products', 'categoryIdNav'));
}
示例5: update
public function update(UpdateCategoryRequest $request, $id)
{
$category = Category::findOrFail($id);
$category->update($request->all());
session()->flash('flash_message', message('user_successfully_updated_category'));
return redirect('/categories/manage');
}
示例6: update
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(CategoryRequest $request, $id)
{
$category = Category::findOrFail($id);
$category->update($request->all());
flash('Category has been updated');
return Redirect::back();
}
示例7: boot
/**
* Define your route model bindings, pattern filters, etc.
*
* @param \Illuminate\Routing\Router $router
* @return void
*/
public function boot(Router $router)
{
// bind article
$router->model('article', 'App\\Article');
$router->bind('admin.article', function ($id) {
return \App\Article::findOrFail($id);
});
// bind category
$router->model('category', 'App\\Category');
$router->bind('admin.category', function ($id) {
return \App\Category::findOrFail($id);
});
// bind language
$router->model('language', 'App\\Language');
$router->bind('admin.language', function ($id) {
return \App\Language::findOrFail($id);
});
// bind language
$router->model('page', 'App\\Page');
$router->bind('admin.page', function ($id) {
return \App\Page::findOrFail($id);
});
// bind setting
$router->model('setting', 'App\\Setting');
$router->bind('admin.setting', function ($id) {
return \App\Setting::findOrFail($id);
});
// bind user
$router->model('user', 'App\\User');
$router->bind('admin.user', function ($id) {
return \App\User::findOrFail($id);
});
parent::boot($router);
}
示例8: update
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(CategoryRequest $request)
{
$category = Category::findOrFail($request->get('id'));
$category->name = $request->get('name');
$category->save();
return \Redirect::route('index-category')->with('message', 'Record has been Saved');
}
示例9: destroy
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
$category = Category::findOrFail($id);
$category->delete();
flash()->success('Category Deleted!');
return redirect()->route('categories.index');
}
示例10: update
/**
* Update the specified category in storage.
* @param UpdateCategoryRequest|Request $request
*
* @param int $id
*/
public function update($id, UpdateCategoryRequest $request)
{
$category = Category::findOrFail($id);
$request = $this->saveFiles($request);
$category->update($request->all());
return redirect()->route('admin.category.index');
}
示例11: sort
public function sort($id, Request $request)
{
$order = $request->order;
$category = Category::findOrFail($id);
$products = Product::where('category_id', '=', $id);
switch ($order) {
case "1":
$products = $products->orderByName()->get();
break;
case "2":
$products = $products->orderByName("DESC")->get();
break;
case "3":
$products = $products->orderByPrice('DESC')->get();
break;
case "4":
$products = $products->orderByPrice()->get();
break;
default:
$products = $products->get();
break;
}
if (!$this->auth->guest()) {
foreach ($products as $product) {
$product->discountPrice();
}
} else {
$products = $products->filter(function ($products) {
return !$products->isOffer();
});
}
return View::make('category.product', array('products' => $products, 'actualCategory' => $category, 'selected' => $order));
}
示例12: showProductByCategory
public function showProductByCategory($id, $slug = '')
{
$category = Category::findOrFail($id);
$products = $category->products()->with('tags', 'category', 'picture')->paginate(5);
$title = " Welcome category page {$category->title}";
return view('front.category', compact('products', 'title'));
}
示例13: category
public function category($id)
{
$categories = $this->categories();
$articles = Category::findOrFail($id)->articles()->orderBy('id', 'desc')->paginate(10);
$category = Category::findOrFail($id);
return view('home.category', compact('categories', 'articles', 'category'));
}
示例14: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store(QuizRequest $request)
{
$cat = Category::findOrFail($request->input('cat_list'));
$quiz = $cat->quizzes()->create($request->all());
flash()->success('New Quiz has been created!');
return redirect('quizzes');
}
示例15: updateCategories
public function updateCategories(Request $request)
{
foreach ($request->all() as $id => $data) {
if ($id !== '_token') {
if ($data['type'] == 'remove' && $id >= 1) {
$found = Category::findOrFail($id);
if ($found->products->isEmpty()) {
$found->delete();
}
} else {
if ($data['name'] !== '' && $data['type'] !== '') {
if ($id >= 1) {
$found = Category::findOrFail($id);
} else {
$found = new Category();
}
$found->name = $data['name'];
$found->type = $data['type'];
$found->save();
}
}
}
}
return redirect()->route('categories.index');
}