本文整理汇总了PHP中Category::findOrFail方法的典型用法代码示例。如果您正苦于以下问题:PHP Category::findOrFail方法的具体用法?PHP Category::findOrFail怎么用?PHP Category::findOrFail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Category
的用法示例。
在下文中一共展示了Category::findOrFail方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: show
public function show($id)
{
$category = Cache::want('category_' . $id, 0, function () use($id) {
return Category::findOrFail($id);
});
$articles = Article::with('tags')->where('cid', '=', $category->id)->orderBy('id', 'desc')->paginate(15);
$values = array('title' => $category->name . '_', 'category' => $category, 'articles' => $articles);
return View::make('category.show', $values);
}
示例2: update
/**
* Update the specified category in storage.
*
* @param int $id
* @return Response
*/
public function update($id)
{
$category = Category::findOrFail($id);
$validator = Validator::make($data = Input::all(), Category::$rules);
if ($validator->fails()) {
return Redirect::back()->withErrors($validator)->withInput();
}
$category->update($data);
return Redirect::route('categories.index');
}
示例3: delete
/**
* Delete Category, related Albums & Images
*
* @param int $categoryId
*
* @return \Illuminate\View\View | \Illuminate\Http\RedirectResponse
*/
public function delete($categoryId)
{
$category = Category::findOrFail($categoryId);
if (Request::isMethod('GET')) {
return View::make('category.delete', compact('category'));
} elseif (Request::isMethod('POST')) {
$category->delete();
return Redirect::to('/categories')->with('success', 'Category deleted');
}
}
示例4: tree
public function tree(Request $request)
{
$parent_id = $request->input('parent_id', 0);
$query = $this->resources;
if ($parent_id) {
$parent = Category::findOrFail($parent_id);
$query->where('parents', 'LIKE', "{$parent->parents}/{$parent_id}/%");
}
$categories = $query->get();
return make_tree($categories);
}
示例5: delete
/**
* Delete Album & related Images
*
* @param int $categoryId
* @param int $albumId
*
* @return \Illuminate\View\View | \Illuminate\Http\RedirectResponse
*/
public function delete($categoryId, $albumId)
{
$category = Category::findOrFail($categoryId);
$album = Album::findOrFail($albumId);
if (Request::isMethod('GET')) {
return View::make('album.delete', compact('category', 'album'));
} elseif (Request::isMethod('POST')) {
$album->delete();
return Redirect::to('/categories/' . $categoryId . '/albums')->with('success', 'Album deleted');
}
}
示例6: update
/**
* Update the specified category in storage.
*
* @param int $id
* @return Response
*/
public function update($id)
{
$category = Category::findOrFail($id);
$rules = array('name' => 'required');
$validator = Validator::make($data = Input::all(), $rules);
if ($validator->fails()) {
return Redirect::back()->withErrors($validator)->withInput();
}
$category->update($data);
return Redirect::route('admin.categories.index')->with('message', 'Item had updated!');
}
示例7: putEdit
public function putEdit()
{
$id = Input::get('id');
$rules = ['name' => 'required', 'slug' => 'required'];
$messages = ['name.required' => Config::get('site.validate.name.required'), 'slug.required' => Config::get('site.validate.slug.required')];
$validator = Validator::make(Input::all(), $rules, $messages);
if ($validator->fails()) {
return Redirect::to('/admin/cat/edit/' . $id)->withErrors($validator);
}
$category = Category::findOrFail($id);
$category->name = Input::get('name');
$category->slug = Str::slug(Input::get('slug'), '-');
$category->save();
Cache::flush();
return Redirect::to('/admin/cat');
}
示例8: post_categoriesedit
public function post_categoriesedit($id)
{
//Get our fields
$name = Input::get('categoryName');
$parent = Input::get('categoryParent');
$validator = Validator::make(array('id' => $id, 'name' => $name, 'parent' => $parent), array('id' => 'required|integer', 'name' => 'required', 'parent' => 'integer'), array('id.required' => 'The category ID was not included with the request. This is an internal error. ', 'id.integer' => 'Invalid category ID format. This is an internal error.', 'name.required' => 'You forgot to enter a name. Please enter a name and try again.'));
if ($validator->fails()) {
// The given data did not pass validation
$messages = $validator->messages();
$errorStr = '';
$count = count($messages);
$i = 0;
foreach ($messages->all(':message') as $message) {
$i++;
$errorStr .= '<span>' . $message . '</span>';
if ($i != $count) {
$errorStr .= '<br /><hr />';
}
}
return Redirect::to('console/categories/edit/' . $id)->with('message', $errorStr);
}
//Great all of our validation is done. Hey, not so fast. Let's make sure that we are in fact modifying a valid category and the parent exists
//Pull the category
$category = Category::findOrFail($id);
if ($parent != 0) {
$check = Category::where('id', '=', $parent)->where('parentid', '=', '0')->firstOrFail();
}
$category->name = $name;
$category->parentid = $parent;
if (Input::get('categoryHidden') == 1) {
$category->hidden = 1;
} else {
$category->hidden = 0;
}
$category->save();
//Great, all done. Now to redirect the user.
return Redirect::route('consolecategories')->with('message', 'Category successfully updated.');
}
示例9: find
/**
* @param $id
* @return mixed
*/
public function find($id)
{
return $this->category->findOrFail($id);
}
示例10: edit
public function edit($id)
{
$category = Category::findOrFail($id);
return View::make('categories.edit')->with('category', $category)->with('title', "Edit category");
}
示例11: getDelete
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return Response
*/
public function getDelete($id)
{
if (Session::get('user_level') < Config::get('cms.deleteCategory')) {
return Redirect::to(_l(URL::action('AdminHomeController@getIndex')))->with('message', Lang::get('admin.notPermitted'))->with('notif', 'warning');
}
try {
$category = Category::findOrFail($id);
$category->delete();
$category->newsCategories()->delete();
return Redirect::to(_l(URL::action('CategoryController@getIndex')))->with('message', Lang::get('admin.categoryDeleted'))->with('notif', 'success');
} catch (Exception $e) {
return Redirect::to(_l(URL::action('CategoryController@getIndex')))->with('message', Lang::get('admin.noSuchCategory'))->with('notif', 'danger');
}
}
示例12: show
/**
* Display the specified resource.
*
* @param int $id
* @return Response
*/
public function show($id)
{
$category = $this->category->findOrFail($id);
return View::make('categories.show', compact('category'));
}
示例13: post_getvasbycategory
public function post_getvasbycategory()
{
$id = Input::get('data');
$category = Category::findOrFail($id);
$vas = User::where('categories', 'like', '%' . $id . ',%')->where('status', '=', '1')->orderBy('vaname', 'ASC')->get();
if (count($vas) == 0) {
echo '<h4>No Virtual Airlines Found.</h4>';
} else {
$maxwidth = Setting::fetch('banner_maxwidth');
$output = '';
foreach ($vas as $va) {
//There is the potential that another number is before the category id and it got put in with this so let's double check this is just for this category
$categories = explode(',', $va->categories);
array_pop($categories);
if (!in_array($id, $categories)) {
continue;
}
$va->description = html_entity_decode($va->description);
$va->vaname = html_entity_decode($va->vaname);
$va->url = html_entity_decode($va->url);
$banner_directory = $banner_directory = rtrim(Setting::fetch('banner_directory'), '/') . '/';
$banner = '';
if ($va->banner) {
$banner = User::getBannerUrl($va->cid, $banner_directory);
$output .= '<div class="bannerbg"><a target="_blank" href="' . URL::to('/click') . '/' . $va->cid . '"><img style="max-width:' . $maxwidth . ';" class="img-polaroid" src="' . $banner . '" alt="Banner" /></a></div><div class="well"><a target="_blank" href="' . URL::to('/click') . '/' . $va->cid . '"><h4>' . $va->vaname . '</h4></a><blockquote style="margin-top: 4px;">' . $va->description . '</blockquote></div>';
} else {
$output .= '<div class="well"><a target="_blank" href="' . URL::to('/click') . '/' . $va->cid . '"><h4>' . $va->vaname . '</h4></a><blockquote style="margin-top: 4px;">' . $va->description . '</blockquote></div>';
}
}
echo $output;
}
}
示例14: function
View::composer('view_user_profile', function ($view) {
$id = $view->getData()["id"];
$data["user"] = User::findOrFail($id);
$data["posts"] = $data["user"]->posts()->get();
$data["comments"] = $data["user"]->comments()->get();
$view->with('data', $data);
});
View::composer('article_edit', function ($view) {
$id = $view->getData()["data"]["id"];
if (isset($view->getData()["data"]["message"])) {
$data["message"] = $view->getData()["data"]["message"];
}
$data["post"] = Post::findOrFail($id);
$view->with('data', $data);
});
View::composer('category_view', function ($view) {
$id = $view->getData()["id"];
$data["category"] = Category::findOrFail($id);
$data["posts"] = $data["category"]->post()->paginate(5);
$view->with('data', $data);
});
View::composer('admin_page', function ($view) {
$data["posts"] = Post::orderBy('id', 'DESC')->get()->take(10);
$data["unmoderated"] = Post::where('moderated', '=', false)->orderBY('id', 'DESC')->get()->take(10);
$data["comments"] = Comment::orderBy('id', 'DESC')->get()->take(10);
$view->with('data', $data);
});
View::composer('manage_users', function ($view) {
$data["users"] = User::orderBy('id', 'DESC')->paginate(5);
$view->with('data', $data);
});
示例15: update
/**
* Update the specified category in storage.
*
* @param int $id
* @return Response
*/
public function update($id)
{
$category = Category::findOrFail($id);
$validator = Validator::make($data = Input::all(), Category::$rules);
if ($validator->fails()) {
return Redirect::back()->withErrors($validator)->withInput();
}
if ($category->update($data)) {
//Show message
$alert[] = ['class' => 'alert-success', 'message' => '<strong><i class="fa fa-check"></i></strong> Atualizado!'];
Session::flash('alerts', $alert);
}
return Redirect::to(URL::previous());
}