StevenThelin
StevenThelin

Reputation: 235

Laravel: Inner join QueryException

I'm trying to perform a join between tables in Laravel. However i receive this, when loading the page:

QueryException in Connection.php line 651:

This is the query:

$patches = DB::table('or_patches')
    ->join('or_clients', function($join) use($authid)
    {
        $join->on('or_patches.client_id', '=', 'or_clients.id')
        >where('or_clients.customer_id'. '=', $authid);
    })
    ->get();

It doesn't work either, if i remove use(), and build the "where" upon a static value.

Detailed error:

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an 
error in your SQL syntax; check the manual that corresponds to your 
MySQL server version for the right syntax to use near '1 ?' at line 1 
(SQL: select * from `or_patches` inner join `or_clients` on 
`or_patches`.`client_id` = `or_clients`.`id` and 
`or_clients`.`customer_id=` 1 )

Does anyone know why? I've tried using left joins as well, without success.

UPDATE: Tried changing "." to "," in the where clause. This fixed the issue. Thanks @AlexRussel.

Upvotes: 0

Views: 166

Answers (1)

alexrussell
alexrussell

Reputation: 14202

From the look of the SQL error (problem with the SQL ...`or_clients.customer_id=` 1) you're getting the = from your query affixed to the field name. Taking a look at the code, it looks just like a simple typo where you're using . instead of , in a method call, thus concatenating the = to the field:

>where('or_clients.customer_id'. '=', $authid);

Should be:

->where('or_clients.customer_id', '=', $authid);

Upvotes: 1

Related Questions