本文整理汇总了PHP中app\Post::join方法的典型用法代码示例。如果您正苦于以下问题:PHP Post::join方法的具体用法?PHP Post::join怎么用?PHP Post::join使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Post
的用法示例。
在下文中一共展示了Post::join方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index
/**
* 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: index
/**
* 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: getJoinsData
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: getPopular
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: buscar
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];
}