Well, just to make it as an answer: you should specify the table to which confirm
is related.
$q->where('course_team.confirm',1);
Pergunta
I'm having trouble using whereHas, here is the code:
<?php
$courses = Course::whereHas('teams', function($q)
{
$q->where('confirm',1);
})->get();
// $courses = Course::has('teams')->get();
?>
Error:
SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'confirm' in where clause is ambiguous (SQL: select * from `courses` where (select count(*) from `teams` inner join `course_team` on `teams`.`id` = `course_team`.`team_id` where `course_team`.`course_id` = `courses`.`id` and `confirm` = 1) >= 1) (View: /Applications/MAMP/htdocs/learnvenue/app/views/dashboard/trainer/index.blade.php)
open: /Applications/MAMP/htdocs/learnvenue/vendor/laravel/framework/src/Illuminate/Database/Connection.php
}
// If an exception occurs when attempting to run a query, we'll format the error
// message to include the bindings with SQL, which will make this exception a
// lot more helpful to the developer instead of just the database's errors.
catch (\Exception $e)
{
throw new QueryException($query, $bindings, $e);
}
what i want to do is that to get courses which they have teams assigned to them where in pivot table:'course_team' the 'confirm' column is 'true'
has() method for just getting courses that have teams working fine,
How do I get this working?
Solução
Well, just to make it as an answer: you should specify the table to which confirm
is related.
$q->where('course_team.confirm',1);