当前位置: 首页>>代码示例>>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;未经允许,请勿转载。