I'm learning Yii2 framework and PHP, and I can't find solution to my problem.
I have AR Model Project with many-to-many relation:
public function getUsers() {
return $this->hasMany(UserAR::className(), ['id' => 'user_id'])
->viaTable('user_project', ['project_id' => 'id']);
}
I want to retrieve all projects with User of given ID, And reverse - all projects without this user. So far I tried it this way:
$uid = Yii::$app->user->id;
$projects = Project::find()->all();
foreach($projects as $p){
$found = $p->getUsers()->where(['id'=>$uid])->all();
echo"<pre>"; var_dump($found);
}
but it returns NULL
for every iteration,
What I'm doing wrong?