Пример #1
0
 public function index()
 {
     if (Auth::check()) {
         $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')->paginate(10);
         return view('timeline.index')->with('statuses', $statuses);
     }
     return view('home');
 }
Пример #2
0
 public function index()
 {
     //IF THE USER IS LOGGED IN, IT WILL SHOW A DIFFERENT LAYOUT THAN THE RETURN VIEW
     if (Auth::check()) {
         $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')->paginate(2);
         return view('timeline.index')->with('statuses', $statuses);
     }
     return view('home');
 }
Пример #3
0
 public function getLike($statusId)
 {
     $status = Status::find($statusId);
     if (!$status) {
         return redirect()->route('home');
     }
     if (!Auth::user()->isFriendsWith($status->user)) {
         return redirect()->route('home');
     }
     if (Auth::user()->hasLikedStatus($status)) {
         return redirect()->back();
     }
     $like = $status->likes()->create([]);
     Auth::user()->likes()->save($like);
     return redirect()->back();
 }
Пример #4
0
 /**
  * Unliking using AJAX
  */
 public function postUnlike($statusId, Request $request)
 {
     $status = Status::find($statusId);
     $likes = $status->likes->count();
     if (!$status) {
         return response()->json(['response' => false, 'likes' => $likes, 'id' => $status->id, 'value' => 'Like', 'message' => 'Status not found', 'url' => route('status.like', ['statusId' => $status->id])]);
     } else {
         if (!Auth::user()->hasLikedStatus($status)) {
             return response()->json(['response' => false, 'likes' => $likes, 'id' => $status->id, 'value' => 'Like', 'message' => 'Already unliked', 'url' => route('status.like', ['statusId' => $status->id])]);
         }
     }
     Auth::user()->likes()->delete($status);
     if (!$request->ajax()) {
         return redirect()->back();
     }
     $status = Status::find($statusId);
     $message = ['response' => true, 'likes' => $status->likes->count(), 'url' => route('status.like', ['statusId' => $status->id]), 'id' => $status->id, 'value' => 'Like'];
     return response()->json($message);
 }