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


PHP Article::findOrFail方法代码示例

本文整理汇总了PHP中app\Article::findOrFail方法的典型用法代码示例。如果您正苦于以下问题:PHP Article::findOrFail方法的具体用法?PHP Article::findOrFail怎么用?PHP Article::findOrFail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app\Article的用法示例。


在下文中一共展示了Article::findOrFail方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: boot

 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     //
     parent::boot($router);
     $router->bind('articles', function ($id) {
         $article = Article::findOrFail($id);
         // If the owner return all articles else return only published.
         if (Auth::user() && $article->user_id === Auth::user()->id) {
             $articles = Article::findOrFail($id);
         } else {
             $articles = Article::published()->findOrFail($id);
         }
         return $articles;
     });
     $router->bind('questions', function ($id) {
         return Question::findOrFail($id);
     });
     $router->bind('answers', function ($id) {
         return Answer::findOrFail($id);
     });
     $router->bind('tags', function ($name) {
         return Tag::where('name', $name)->firstOrFail();
     });
     $router->bind('users', function ($id) {
         return User::findOrFail($id);
     });
 }
开发者ID:nilstr,项目名称:stackoverflow-clone,代码行数:33,代码来源:RouteServiceProvider.php

示例2: 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);
 }
开发者ID:abada,项目名称:laravel-5-simple-cms,代码行数:40,代码来源:RouteServiceProvider.php

示例3: blogShow

 public function blogShow($id)
 {
     $article = Article::findOrFail($id);
     $user = $article->user;
     $photos = count($article->photos);
     return view('blog.show', compact('article', 'photos', 'user'));
 }
开发者ID:myleshyson,项目名称:ivgainesville,代码行数:7,代码来源:SiteController.php

示例4: update

 public function update($id, \Illuminate\Http\Request $request)
 {
     $this->validate($request, ['name' => 'required', 'text' => 'required']);
     $article = Article::findOrFail($id);
     $article->update($request->all());
     return redirect('articles');
 }
开发者ID:shpikyliak,项目名称:laravel5_test,代码行数:7,代码来源:ArticlesController.php

示例5: update

 public function update($id, ArticleRequest $request)
 {
     $article = Article::findOrFail($id);
     $article->tags()->sync($request->input('tag_list'));
     $article->update($request->all());
     return redirect('articles');
 }
开发者ID:JohnathanBere,项目名称:laraproject,代码行数:7,代码来源:ArticlesController.php

示例6: show

 public function show($id)
 {
     $article = Article::findOrFail($id);
     $categories = $this->categories();
     $tags = Tag::all();
     return view('home.single', compact('article', 'categories', 'tags'));
 }
开发者ID:axhello,项目名称:laravel-blog-demo,代码行数:7,代码来源:HomeController.php

示例7: update

 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     $this->check($request);
     $article = Article::findOrFail($id);
     $article->update($request->all());
     return redirect('/admin/articles');
 }
开发者ID:sandywalker,项目名称:xiehouxing,代码行数:14,代码来源:AdminArticleController.php

示例8: showArticle

 public function showArticle($id)
 {
     $article = Article::findOrFail($id);
     $news = Article::where('id', '>', $article->id)->orderBy('id', 'DESC')->take(NEW_OLD_ARTICLE);
     $olds = Article::where('id', '<', $article->id)->orderBy('id', 'DESC')->take(NEW_OLD_ARTICLE);
     return view('frontend.articles.main')->with(compact('news', 'article', 'olds'));
 }
开发者ID:louisthaihv,项目名称:colong,代码行数:7,代码来源:IndexController.php

示例9: update

 public function update($id, Request $request)
 {
     $this->validate($request, ['title' => 'required', 'description' => 'required']);
     $article = Article::findOrFail($id);
     $article->update($request->all());
     return redirect('articles');
 }
开发者ID:jetmirhaxhisefa,项目名称:learning-laravel-5,代码行数:7,代码来源:ArticleController.php

示例10: update

 /**
  * Update the specified resource in storage.
  *
  * @param int $id
  *
  * @return Response
  */
 public function update(ArticleRequest $request, $id)
 {
     $article = Article::findOrFail($id);
     $article->update($request->all());
     $this->syncTags($article, $request->input('tag_list'));
     return redirect('admin/articles/index');
 }
开发者ID:kpaxer,项目名称:laravel-blog,代码行数:14,代码来源:ArticlesController.php

示例11: showarticle

 public function showarticle($id)
 {
     $choosenLang = \Session::get('locale');
     $tags = Tag::where('lang', '=', $choosenLang)->get();
     $article = Article::findOrFail($id);
     return view('showarticle', compact('article', 'tags'));
 }
开发者ID:ramigit3D,项目名称:article,代码行数:7,代码来源:HomeController.php

示例12: update

 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Requests\ArticleRequest $request, $id)
 {
     $article = Article::findOrFail($id);
     $article->update($request->all());
     $article->tags()->sync($request->get('tag_list', []));
     return redirect()->action('Goenitz\\ArticleController@index');
 }
开发者ID:tianyirenjian,项目名称:laravel-blog,代码行数:14,代码来源:ArticleController.php

示例13: update

 public function update($id, ClanakRequest $request)
 {
     $clanak = Article::findOrFail($id);
     $clanak->update($request->all());
     Session::flash('flash_message', 'Uspjesno ste izmjenili clanak');
     return redirect('clanak');
 }
开发者ID:uros262,项目名称:test_projekat_blog_laravel5,代码行数:7,代码来源:KontrolerClanaka.php

示例14: update

 public function update($id, Requests\ArticleRequest $request)
 {
     $article = Article::findOrFail($id);
     $article->update($request->all());
     $tagIds = $request->input('tag_list');
     $this->syncTags($article, $tagIds);
     return redirect('articles');
 }
开发者ID:cronycles,项目名称:learning-laravel-5,代码行数:8,代码来源:ArticlesController.php

示例15: showpost

 public function showpost($id)
 {
     //display one post
     $article = Article::findOrFail($id);
     $comment = Comment::where('postid', '=', $id)->get();
     //if (is_null($article)) {  abort(404); }
     return view('articles.show', compact('article', 'comment'));
 }
开发者ID:leloulight,项目名称:bloga,代码行数:8,代码来源:PagesController.php


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