コード例 #1
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     //
     //$posts = Post::select('id', 'headline')->orderBy('created_at', 'DESC')->get();
     // Get this post comments
     //$posts = $this->post->select('id', 'headline')->orderBy('created_at', 'DESC')->get();
     $posts = Post::join('users', function ($join) {
         $join->on('posts.user_id', '=', 'users.id');
     })->select('posts.id', 'posts.headline', DB::raw('CONCAT(users.first_name, " ", users.last_name) AS full_name'), 'posts.publish_date')->orderBy('posts.id', 'DESC')->get();
     return view('posts.index', compact('posts'));
     /*
     if(Sentinel::getUser()->inRole('admins')) {      
     	$posts = $this->post->orderBy('created_at', 'DESC')->paginate(25); 
     }else{        
     	        $user = Sentinel::getUser()->id;
     	        $posts = $this->post->where('user_id', $user)->orderBy('created_at', 'DESC')->paginate(25);
     }
     */
     //return view('posts.index', compact('posts'));
 }
コード例 #2
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $forum_groups = App\Forum_group::all();
     $forums = App\Forum::all();
     foreach ($forum_groups as $group) {
         $arr = [];
         foreach ($forums as $forum) {
             if ($group->id == $forum->forum_group_id) {
                 $arr[] = $forum;
             }
         }
         $group->forums = $arr;
         foreach ($group->forums as $forum) {
             $forum->post_count = App\Post::join('threads', 'threads.id', '=', 'posts.thread_id')->join('forums', 'threads.forum_id', '=', 'forums.id')->where('threads.forum_id', '=', $forum->id)->count();
             $forum->thread_count = App\Thread::where('forum_id', '=', $forum->id)->count();
             $forum->latest = App\Post::select('users.username', 'posts.*', 'threads.title')->join('threads', 'threads.id', '=', 'posts.thread_id')->join('forums', 'threads.forum_id', '=', 'forums.id')->join('users', 'users.id', '=', 'posts.user_id')->where('forums.id', '=', $forum->id)->orderBy('posts.created_at', 'desc')->first();
         }
     }
     $this->data['forum_groups'] = $forum_groups;
     return view('forum.index', $this->data);
 }
コード例 #3
0
 public function getJoinsData()
 {
     $posts = Post::join('users', 'posts.user_id', '=', 'users.id')->select(['posts.id', 'posts.title', 'users.name', 'users.email', 'posts.created_at', 'posts.updated_at']);
     return Datatables::of($posts)->editColumn('title', '{!! str_limit($title, 60) !!}')->editColumn('name', function ($model) {
         return \HTML::mailto($model->email, $model->name);
     })->make(true);
 }
コード例 #4
0
ファイル: Category.php プロジェクト: ambarsetyawan/brewski
 public static function getPopular($limit = 5)
 {
     $categories = Post::join('category_post', 'category_post.post_id', '=', 'posts.id')->join('categories', 'categories.id', '=', 'category_post.category_id')->select(DB::raw('categories.name, categories.slug, count(category_post.id) as cat_count'))->groupBy('categories.id')->limit($limit)->get();
     return $categories;
 }
コード例 #5
0
 public function buscar($app, $id, $query)
 {
     $posts = Post::join('users', 'users.id', '=', 'posts.user_id')->where('posts.estado', 'like', "%{$query}%")->orWhere('posts.cidade', 'like', "%{$query}%")->orWhere('posts.bairro', 'like', "%{$query}%")->select('users.nome_completo as usernome', 'users.username', 'users.picprofile', 'users.id as iduser', 'posts.*')->orderBy('posts.created_at', 'posts,estado', 'posts.cidade', 'posts.bairro')->get();
     foreach ($posts as $key => $post) {
         $post['coments'] = Atividade::where('tipo', 'coment')->where('post_id', $post->id)->join('users', 'users.id', '=', 'atividade.user_send')->select('atividade.*', 'users.username', 'users.id as iduser')->get();
         $post['sumiu'] = Atividade::where('tipo', 'sumiu')->where('post_id', $post->id)->join('users', 'users.id', '=', 'atividade.user_send')->select('atividade.*', 'users.username', 'users.id as iduser')->get();
         $post['esta_aqui'] = Atividade::where('tipo', 'esta_aqui')->where('post_id', $post->id)->join('users', 'users.id', '=', 'atividade.user_send')->select('atividade.*', 'users.username', 'users.id as iduser')->get();
     }
     return ['status' => 'sucesso', 'response' => $posts];
 }