I'm now trying this:
->leftJoin(function($query)
{
if(Input::get('lookingfor'))
{
$query->leftJoin('lookingfor_post','posts.id', '=', 'lookingfor_post.post_id');
}
})
and getting:
Missing argument 2 for Illuminate\Database\Query\Builder::leftJoin(), called in /var/www/CSGO_TF/app/controllers/PostController.php on line 72 and defined
Alright I figured it out.
Instead of trying to chain everything together into one I changed:
$posts = DB::table('posts')
to
$query = DB::table('posts')
And split the rest off:
if (Input::get('lookingfor')) {
$query->leftJoin('lookingfor_post','posts.id', '=', 'lookingfor_post.post_id')
// Lookingfor filter
->where(function($query)
{
if(Input::get('lookingfor'))
{
$query->where('lookingfor_post.lookingfor_id', '=', Input::get('lookingfor'));
}
});
}
$posts = $query->orderBy('id', 'DESC')->paginate(10);
return View::make('posts/index', compact('posts', 'region_options', 'rank_options', 'lookingfor_options', 'minrank', 'maxrank', 'region', 'lookingfor'));
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community