I’m trying to transform a PostGreSQL Query in Laravel Query Builder Syntax, but isn’t working
SELECT users.*, rifs.rif
FROM users
JOIN rif_user on users.id = rif_user.user_id
JOIN rifs ON rifs.id = rif_user.rif_id
WHERE email = '[email protected]';
$busq = DB::table(['users','rifs'])
->select('rifs.nombre','users.email','rifs.rif')
->join('rif_user','users.id', '=', 'rif_user.user_id')
->join('rifs', 'rifs.id', '=', 'rif_user.rif_id')
->where('email' ,'[email protected]')
->get();
I Try the code on Laravel Tinker and there is the Output:
->select(‘rifs.nombre’,’users.email’,’rifs.rif’)
PHP Parse error: Syntax error, unexpected T_OBJECT_OPERATOR on line 1
->join(‘rif_user’,’users.id’, ‘=’, ‘rif_user.user_id’)
PHP Parse error: Syntax error, unexpected T_OBJECT_OPERATOR on line 1
->join(‘rifs’, ‘rifs.id’, ‘=’, ‘rif_user.rif_id’)
PHP Parse error: Syntax error, unexpected T_OBJECT_OPERATOR on line 1
->where(’email’ ,’[email protected]’)
PHP Parse error: Syntax error, unexpected T_OBJECT_OPERATOR on line 1
->get();
2
Answers
$busq = DB::table('users','rifs')->select('rifs.nombre','users.email','rifs.rif')->join('rif_user','users.id', '=', 'rif_user.user_id')->join('rifs', 'rifs.id', '=', 'rif_user.rif_id')->where('email' ,'[email protected]')->get();
i done it puting all code in a single line
Try creating an alias for each table, like this