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


PHP News::findOrFail方法代码示例

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


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

示例1: postComment

 public function postComment(Request $request, $news_id)
 {
     $this->validate($request, ['type' => 'in:agree,disagree', 'content' => 'required|between:1,100']);
     $news = News::findOrFail($news_id);
     $comment = new Comment(['type' => $request->type, 'content' => $request->content, 'user_id' => Auth::user()->id]);
     $news->comments()->save($comment);
     return json_encode(['comments' => $this->comment->forNews($news_id)]);
 }
开发者ID:cntjmj,项目名称:Laralog,代码行数:8,代码来源:ApiController.php

示例2: news

 public function news($news_id)
 {
     $user_id = 0;
     if (Auth::check()) {
         $user_id = Auth::user()->id;
     }
     $script = "<script>\n\t\tvar news_id = {$news_id};\n\t\tvar user_id={$user_id};\n\t</script>";
     $news = News::findOrFail($news_id);
     try {
         DB::beginTransaction();
         $news->increment("visit");
         $news->save();
         DB::commit();
     } catch (Exception $exception) {
         DB::rollback();
     }
     return view('pages.news', ['ngController' => 'NewsController', 'title' => $news->title, 'news' => $news->parse(), 'script' => $script]);
 }
开发者ID:cntjmj,项目名称:Laralog,代码行数:18,代码来源:HomeController.php

示例3: postDelete

 public function postDelete(Request $request, $id)
 {
     $news = News::findOrFail($id);
     $news->delete();
     return redirect()->action('NewsController@getIndex');
 }
开发者ID:sasik-github,项目名称:system.pro,代码行数:6,代码来源:NewsController.php

示例4: getComments

 public function getComments(Request $request, $newsId)
 {
     $news = News::findOrFail($newsId);
     $querys = $request->query();
     $comments = $news->getComments()->orderBy('created_at', 'desc');
     if (isset($querys['author_id']) && is_numeric($querys['author_id'])) {
         $author_id = (int) $querys['author_id'];
         $comments = $comments->where('author_id', $author_id);
     }
     $page = 1;
     if (isset($querys['page']) && is_numeric($querys['page'])) {
         $page = (int) $querys['page'];
     }
     $pageSize = 20;
     if (isset($querys['per_page']) && is_numeric($querys['per_page'])) {
         $pageSize = (int) $querys['per_page'];
     }
     $totalCount = count($comments->get());
     $skip = $pageSize * ($page - 1);
     $comments = $comments->skip($skip)->take($pageSize)->get();
     foreach ($comments as $comment) {
         $comment = $this->unfoldCommentInfo($comment);
     }
     $result = array('page' => $page, 'per_page' => $pageSize, 'total_count' => $totalCount, 'data' => $comments);
     return response()->json($result);
 }
开发者ID:xiyou-linuxer,项目名称:cs-restful-api,代码行数:26,代码来源:NewsController.php

示例5: getTags

 public function getTags($id)
 {
     $news = News::findOrFail($id);
     return json_encode($news->Tags());
 }
开发者ID:ghosthels,项目名称:ftproject,代码行数:5,代码来源:NewsController.php

示例6: show

 /**
  * Display the specified News.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     $active = 'news';
     $news = News::findOrFail($id);
     return view('frontend.news.show', compact('active', 'news'));
 }
开发者ID:TawsifKarim,项目名称:ict-mbstu,代码行数:12,代码来源:NewsController.php


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