0

I am trying to figure out why something is happening.

When a Model is created it is given a status parameter. Initially the status is Awaiting Information, but it soon gets changed to Awaiting Acceptance. I am trying to display models on my page only if their status has passed these two stages. At the moment I have the following

$projects = Project::with('client')->where('status', '!=', 'Awaiting Information')->orWhere('status', '!=', 'Awaiting Acceptance')->get();

For some reason however, this returns a project that has the status Awaiting Information. If I remove the orWhere part, then no projects are displayed as is expected. It appears the orWhere is throwing the query off. I am looking to return all projects which do not have these statuses.

Am I missing something here in my clauses?

Thanks

katie hudson
  • 2,765
  • 13
  • 50
  • 93
  • Please prefer this answer, It's helpful for you: [http://stackoverflow.com/questions/25849015/laravel-eloquent-where-not-in] – Hiren Gohel Aug 30 '16 at 11:14

1 Answers1

1

I would suggest you to use whereNotIn method for your query:

$projects = Project::with('client')->whereNotIn('status', ['Awaiting Information', 'Awaiting Acceptance'])->get();
Andrej
  • 7,474
  • 1
  • 19
  • 21