Using Is NOT NULL in query builder

When building where clauses it’s not that well documented how to use NOT and NULL .

Starting with a simple query:

    $post = Post::find()->all();


If we wanted to select all posts where the content had something in it
    $post = Post::find()
      ->where(['not',['content'=>null]])
      ->all();


Note the doubles set of square brackets, first before the ‘not’ and then around the parameters.
So, that could also be
    $post = Post::find()
      ->where([ 'not',[ 'content'=>null, 'status' => 1 ]])
      ->all();


Which would equate to content is not null and status not equal 1.

Let’s Start a Project!

Contact Me