當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Article::findOrFail方法代碼示例

本文整理匯總了PHP中app\models\Article::findOrFail方法的典型用法代碼示例。如果您正苦於以下問題:PHP Article::findOrFail方法的具體用法?PHP Article::findOrFail怎麽用?PHP Article::findOrFail使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在app\models\Article的用法示例。


在下文中一共展示了Article::findOrFail方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: getArticle

 public function getArticle($id, $api)
 {
     $article = Article::findOrFail($id);
     if ($api) {
         return response()->json($article);
     } else {
         return $article;
     }
 }
開發者ID:RenaudDahl,項目名稱:LumenBlog,代碼行數:9,代碼來源:ArticleController.php

示例2: destroy

 public function destroy($id)
 {
     $article = Article::findOrFail($id);
     if ($article->delete()) {
         return Redirect::to('/user/article');
     } else {
         return Redirect::back()->withInput()->withErrors('更新失敗!');
     }
 }
開發者ID:popohum,項目名稱:Earths-Best,代碼行數:9,代碼來源:ArticleController.php

示例3: testRouteCreateArticleArticleJsonReturned

 /**
  * Calls the creation route of an article
  * and checks the response json and the db.
  **/
 public function testRouteCreateArticleArticleJsonReturned()
 {
     $response = $this->assertOk('POST', '/api/articles', ['title' => 'testing']);
     $this->assertNotNull($response->article);
     $this->assertNotNull($response->article->id);
     $this->assertEquals('testing', $response->article->title);
     $insertedArticle = Article::findOrFail($response->article->id);
     $this->assertNotNull($insertedArticle);
     $this->assertEquals($response->article->title, $insertedArticle->title);
 }
開發者ID:TiagoMaiaL,項目名稱:wiki,代碼行數:14,代碼來源:ArticlesRoutesIntegrationTest.php

示例4: listArticles

 /**
  * Lists the inserted articles
  * either by id, title or none.
  *
  * @param int $id
  * @param str $title
  * @param int $limit
  *
  * @throws Illuminate\Database\Eloquent\ModelNotFoundException
  *
  * @return array
  **/
 public function listArticles($id = null, $title = null, $limit = 20)
 {
     $query = Article::orderBy('created_at');
     if ($id) {
         return Article::findOrFail($id);
     }
     if ($title) {
         return $query->where('title', 'LIKE', '%' . $title . '%')->paginate($limit)->items();
     }
     return $query->paginate($limit)->items();
 }
開發者ID:TiagoMaiaL,項目名稱:wiki,代碼行數:23,代碼來源:ArticlesRepository.php

示例5: updateArticle

 public function updateArticle(Request $request, $id, $api)
 {
     $article = Article::findOrFail($id);
     $article->title = $request->input('title');
     $article->content = $request->input('content');
     $article->save();
     if ($api) {
         return response()->json($article);
     } else {
         return $article;
     }
 }
開發者ID:RenaudDahl,項目名稱:LumenBlog,代碼行數:12,代碼來源:AdminController.php

示例6: update

 public function update($id, ArticleVal $request)
 {
     $file = $request->file('image');
     $destinationPath = base_path() . '/portfolio-assessment/images/featured';
     $filename = $file->getClientOriginalName();
     $file->move($destinationPath, $filename);
     echo $filename;
     //echo '<img src="uploads/'. $filename . '"/>';
     $article = Article::findOrFail($id);
     $user = $article->update(['title' => $request->input('title'), 'image' => $filename, 'body' => $request->input('body'), 'excerpt' => $request->input('excerpt'), 'published_at' => $request->input('published_at'), 'tags' => $request->input('tags')]);
     return redirect()->route('home')->withInfo('Your article has been updated');
 }
開發者ID:shep1990,項目名稱:scorpio_studios,代碼行數:12,代碼來源:ArticleController.php

示例7: createEdition

 /**
  * Creates a new edition on
  * the passed article ID.
  *
  * @param int  $articleID
  * @param str  $editionContent
  * @param User $user
  *
  * @throws ModelNotFoundException
  *
  * @return Edition
  **/
 public function createEdition($articleID, $editionContent, User $user)
 {
     // TODO: Use a repository static method for this
     if (method_exists(Article::class, 'newQuery')) {
         Article::findOrFail($articleID);
     }
     $edition = new Edition();
     $edition->article_id = $articleID;
     $edition->content = $editionContent;
     $edition->created_by = $user->id;
     $edition->save();
     return $edition;
 }
開發者ID:TiagoMaiaL,項目名稱:wiki,代碼行數:25,代碼來源:EditionsRepository.php

示例8: update

 public function update($id)
 {
     $id = intval($id);
     $articleInstance = Article::findOrFail($id);
     $data = Request::only('slag', 'content', 'title');
     if (Request::hasFile('article_image')) {
         $data['image_url'] = upload::upload('asset/article_image/', 'article_image');
     }
     $rules = ['slag' => 'required|max:255', 'title' => 'required|max:255', 'content' => 'required'];
     if (validate::make($data, $rules)) {
         $categories = Request::only('category');
         $articleInstance->update($data);
         $articleInstance->categories()->sync($categories['category']);
         return Redirect::back()->withResult('operation complete');
     } else {
         return Redirect::back()->withResult('whoops!looks like something wrong happened');
     }
 }
開發者ID:Albertao,項目名稱:myblog,代碼行數:18,代碼來源:ArticleAdminController.php

示例9: boot

 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @return void
  */
 public function boot()
 {
     parent::boot();
     Route::bind('article', function ($slug) {
         if (!Auth::user()) {
             return Article::published()->slug($slug)->first();
         }
         return Article::where('slug', $slug)->first() ?: Article::findOrFail((int) $slug);
     });
     Route::bind('tag', function ($slug) {
         if (!Auth::user()) {
             return Tag::slug($slug)->first();
         }
         return Tag::where('slug', $slug)->first() ?: Tag::findOrFail((int) $slug);
     });
     Route::bind('page', function ($id) {
         return Page::find($id);
     });
 }
開發者ID:mattvb91,項目名稱:website-laravel,代碼行數:24,代碼來源:RouteServiceProvider.php

示例10: edit

 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function edit($id)
 {
     $article = Article::findOrFail($id);
     return view('admin.articles.edit', ['article' => $article]);
 }
開發者ID:scotthummel,項目名稱:lambdaphx,代碼行數:11,代碼來源:ArticleController.php

示例11: show

 public function show($id)
 {
     $article = Article::findOrFail($id);
     return view('articles.show', compact('article'));
 }
開發者ID:kongtoonarmy,項目名稱:laravel-l5fundamentals,代碼行數:5,代碼來源:ArticlesController.php

示例12: findWithCreatedAtAndSlug

 public function findWithCreatedAtAndSlug($id, $created_at, $slug)
 {
     return Article::findOrFail($id)->where('created_at', 'LIKE', $created_at . '%')->where('slug', $slug)->first();
 }
開發者ID:sontdhust,項目名稱:eruza,代碼行數:4,代碼來源:ArticleRepository.php

示例13: saveThisArticleRequest

 /**
  * @param Request $request
  * @return Article
  */
 private function saveThisArticleRequest(Request $request)
 {
     $article = new Article();
     $path = storage_path('articles');
     $file = '';
     if ($request->id) {
         $article = Article::findOrFail((int) $request->id);
         $file = $article->file;
     }
     if (!$file) {
         $file = str_random(12) . '.md';
         while (app('files')->exists("{$path}/{$file}")) {
             $file = str_random(12) . '.md';
         }
     }
     app('files')->put("{$path}/{$file}", $request->article);
     $article->title = $request->title;
     $article->slug = $request->title;
     $article->excerpt = str_words($request->article, 20);
     $article->published = $request->published;
     $article->path = $path;
     $article->file = $file;
     $article->author_id = app('auth')->user()->id;
     $article->save();
     return $article;
 }
開發者ID:kishanterry,項目名稱:emdlog,代碼行數:30,代碼來源:ArticlesController.php


注:本文中的app\models\Article::findOrFail方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。