I am printing Sql query below in Laravel
$CheckIfAssigned = Projects::select(DB::Raw('count(projects.id) as projects'))
->leftJoin('project_team as pt', 'projects.id', '=', 'pt.project_id')
->where(DB::Raw('(projects.id = '.$projectId.') AND ( project_manager_id = '.$LoggedInUserId.' OR pt.employee_id = '.$LoggedInUserId.')'))->toSql();
And the Result i am getting is :
select count(projects.id) as projects from `projects` left join
`project_team` as `pt` on `projects`.`id` = `pt`.`project_id`
where (projects.id = 13) AND ( project_manager_id = 9 OR pt.employee_id = 9) is null
Why there is is null
in the Sql Query at the end even i did not write ?
The where
function is expecting a second parameter, and you didn't provide that, the default value of the second parameter is null
, that's why the is null
is appending to your query. You can use the whereRaw
function instead to solve your problem.