Support the ongoing development of Laravel.io →
Input Database Forms
Last updated 2 years ago.
0

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

Last updated 2 years ago.
0

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'));


Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.