當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。