How do I use the conditions "not exist" and "not in" in Yii2? I have a select with the list of users, but want to exclude users who are on the table "user_post"
User
id_user | username
User_post
id_user_post | id_post | id_user
<?= $form->field($model, 'id_user')->dropDownList(
ArrayHelper::map(User::find()
->all(),'id_user','username'),
['prompt' => 'Select User']
) ?>
You can do it like below:
User::find()->where(['not in','user_id',[1,2,3]]);
Which returns Users
with ID's not in [1,2,3]