当前位置: 首页>>代码示例>>PHP>>正文


PHP Category::findOrFail方法代码示例

本文整理汇总了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);
 }
开发者ID:xiaohulidudu,项目名称:laravel-blog,代码行数:9,代码来源:CategoryController.php

示例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');
 }
开发者ID:shittyc0de,项目名称:AplikasiLC,代码行数:16,代码来源:CategoriesController.php

示例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');
     }
 }
开发者ID:developeman,项目名称:Laravel-Image-Archive,代码行数:17,代码来源:CategoryController.php

示例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);
 }
开发者ID:kshar1989,项目名称:dianpou,代码行数:11,代码来源:CategoryController.php

示例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');
     }
 }
开发者ID:developeman,项目名称:Laravel-Image-Archive,代码行数:19,代码来源:AlbumController.php

示例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!');
 }
开发者ID:vnzacky,项目名称:exp_services,代码行数:17,代码来源:CategoriesController.php

示例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');
 }
开发者ID:jgbneatdesign,项目名称:tikwenpam,代码行数:16,代码来源:CatController.php

示例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.');
 }
开发者ID:A-Lawrence,项目名称:VASOPS,代码行数:38,代码来源:ConsoleController.php

示例9: find

 /**
  * @param $id
  * @return mixed
  */
 public function find($id)
 {
     return $this->category->findOrFail($id);
 }
开发者ID:phillipmadsen,项目名称:deved,代码行数:8,代码来源:CategoryRepository.php

示例10: edit

 public function edit($id)
 {
     $category = Category::findOrFail($id);
     return View::make('categories.edit')->with('category', $category)->with('title', "Edit category");
 }
开发者ID:talha08,项目名称:Farmer-Bazar,代码行数:5,代码来源:CategoriesController.php

示例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');
     }
 }
开发者ID:Puskice,项目名称:PuskiceCMS,代码行数:20,代码来源:CategoryController.php

示例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'));
 }
开发者ID:giangcoffee,项目名称:ninja,代码行数:11,代码来源:CategoriesController.php

示例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;
     }
 }
开发者ID:A-Lawrence,项目名称:VASOPS,代码行数:32,代码来源:AjaxController.php

示例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);
});
开发者ID:jtaurus,项目名称:jtauri_blog,代码行数:31,代码来源:composers.php

示例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());
 }
开发者ID:waldenylson,项目名称:alfredapp,代码行数:20,代码来源:CategoriesController.php


注:本文中的Category::findOrFail方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。