示例#1
0
 public function index()
 {
     // Shows timeline if User is Auth
     if (Auth::check()) {
         // Gets status from user and friends
         $statuses = Status::notReply()->where(function ($query) {
             return $query->where('user_id', Auth::user()->id)->orWhereIn('user_id', Auth::user()->friends()->lists('id'));
         })->orderBy('created_at', 'desc')->get();
         return view('timeline.index')->with('statuses', $statuses);
     }
     // If not authenticated user just show home
     return view('home');
 }
示例#2
0
 public function postReply(Request $request, $statusId)
 {
     $this->validate($request, ["reply-{$statusId}" => 'required|max:1000'], ['required' => 'The reply body is required']);
     // Find the status that the reply belongs to
     $status = Status::notReply()->find($statusId);
     // Fail if the status doesn't exist
     if (!$status) {
         return redirect()->route('home');
     }
     // Check if the currently authenticated user is friends with the owner of this status and not his own status
     if (!Auth::user()->isFriendsWith($status->user) && Auth::user()->id !== $status->user->id) {
         return redirect()->route('home');
     }
     // Get the reply
     $reply = Status::create(['body' => $request->input("reply-{$statusId}")])->user()->associate(Auth::user());
     // Reply is saved using the REPLiES method
     $status->replies()->save($reply);
     return redirect()->back();
 }