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


PHP Post::topic方法代碼示例

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


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

示例1: index

 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     // Display the forum index
     // Get the list of forums the user can access
     $accessCollection = Auth::user()->forumAccess;
     // Get the list of forums the user has access to
     $forums = Forum::whereIn('id', $accessCollection)->orderBy('display_order', 'ASC')->get();
     $latestPosts = Post::topic()->with('forum')->whereIn('forum_id', $accessCollection)->orderBy('created_at', 'DESC')->limit(4)->get();
     // Get the online users
     $fiveMinutesAgo = Carbon::now()->subMinutes(5);
     $usersOnline = User::where('active_at', '>=', $fiveMinutesAgo)->orderBy('active_at', 'DESC')->get();
     return view('forums.forum')->withForums($forums)->withLatestPosts($latestPosts)->withOnlineUsers($usersOnline);
 }
開發者ID:unbolt,項目名稱:imp,代碼行數:18,代碼來源:ForumController.php

示例2: store

 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $validator = Validator::make($request->all(), ['topic_id' => 'required|integer', 'content' => 'required']);
     if ($validator->fails()) {
         return response()->json(['errors' => $validator->errors()], 400);
     }
     $topic = Topic::find($request->topic_id);
     // use exception instead later
     if ($topic) {
         $post = new Post();
         $post->content = $request->content;
         $post->user()->associate($this->user);
         $post->topic()->associate($topic);
         $post->save();
     }
     return response()->json(['post' => $post], 201);
 }
開發者ID:uTosTan,項目名稱:codesamples,代碼行數:23,代碼來源:PostController.php

示例3: store

 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $token = JWTAuth::getToken();
     $user = JWTAuth::toUser($token);
     $validator = Validator::make($request->all(), ['title' => 'required|max:255', 'content' => 'required']);
     if ($validator->fails()) {
         return response()->json(['errors' => $validator->errors()], 400);
     }
     $topic = new Topic();
     $topic->title = $request->title;
     $topic->user()->associate($user);
     $topic->save();
     $post = new Post();
     $post->content = $request->content;
     $post->topic()->associate($topic);
     $post->user()->associate($user);
     $post->save();
     return response()->json(['topic' => $topic, 'post' => $post], 201);
 }
開發者ID:uTosTan,項目名稱:codesamples,代碼行數:25,代碼來源:TopicController.php


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