示例#1
0
 public function index()
 {
     $posts = Post::join('users', 'users.id', '=', 'posts.user_id')->select()->orderBy('posts.id', 'desc')->get();
     $numTuits = Post::where('user_id', '=', Auth::user()->id)->count();
     $follows = DB::table('seguidores')->where('user_id', '=', Auth::user()->id)->count();
     $followers = DB::table('seguidores')->where('follow_to', '=', Auth::user()->id)->count();
     $rndUser = User::select()->count();
     $random = rand(1, $rndUser);
     $userFollow = User::find($random);
     return view('index')->with(compact('numTuits', 'posts', 'follows', 'followers', 'userFollow'));
 }
示例#2
0
 public function getProfile(Request $request)
 {
     $username = $request->input('username');
     $id = User::select('id')->where('username', '=', $username)->get();
     if (empty($id)) {
         return redirect()->route('home');
     }
     $userPost = User::find($id[0]->id)->posts;
     $userInfo = User::find($id[0]->id);
     $numTuits = Post::where('user_id', '=', $id[0]->id)->count();
     $follows = DB::table('seguidores')->where('user_id', '=', $id[0]->id)->count();
     $followers = DB::table('seguidores')->where('follow_to', '=', $id[0]->id)->count();
     return view('user.index')->with(compact('userPost', 'userInfo', 'numTuits', 'follows', 'followers'));
 }