Panagiotis Koursaris
Panagiotis Koursaris

Reputation: 4023

InvalidArgumentException in JoinClause.php line 79: Not enough arguments for the on clause

I did query builder with laravel and I've used multiple join in it. When execute the query I get the error Not enough arguments for the on clause. My query builder:

return DB::table('towns_cat_rel')
    ->join('towns', function ($join) {
        $join->on('towns_cat_rel.town_id', '=', 'towns.id')
            ->where('publish', '=', 1);
    })
    ->join('towns_translations', function ($join) {
        $join->on('towns_cat_rel.town_id', '=', 'towns_translations.town_id')
            ->where('locale', '=', \App::getLocale());
    })
    ->join('towns_cat', function ($join) use($categoryID) {
        $join->on('towns_cat.id', '=', 'towns_cat_rel.town_cat_id')
            ->where('towns_cat.id', '=', $categoryID);
    })
    ->join('towns_sub_cat_rel', 'towns_cat_rel.town_id', '=', 'towns_sub_cat_rel.town_id')
    ->join('towns_sub_cat', function ($join) use($subCategoryID) {
        $join->on('towns_sub_cat_rel.town_sub_cat_id', 'towns_sub_cat.id')
            ->where('towns_sub_cat.id', '=', $subCategoryID);
    })
    ->get();

Does anyone know why this happen?

Upvotes: 2

Views: 582

Answers (2)

Panagiotis Koursaris
Panagiotis Koursaris

Reputation: 4023

Sorry Guys! I had forget '=' in the last join => $join->on('towns_sub_cat_rel.town_sub_cat_id', '=', 'towns_sub_cat.id') Now it works fine!

Upvotes: 2

Abid Ali
Abid Ali

Reputation: 1517

I am using laravel5.2 and facing this above error message due to this above code and i resolved with this code, you can modify as per your requirement.

    DB::table('users')
            ->join('contacts', function ($join) {
                $join->on('users.id', '=', 'contacts.user_id')->orOn(...);
            })
        ->get();

Upvotes: 0

Related Questions