Gayan
Gayan

Reputation: 2935

How to use Laravel all() query for exclude some rows

I am studding Laravel, I have table name call "projects". To display all projects I used

$projects= Project::all(); 

But I have project id array like this, I need to remove this projects from resualts

$doNotDisplayThisProjectsIds = array(4, 6, 20);

So how to remove above ids project from result, using Project::all(),

Upvotes: 1

Views: 1069

Answers (1)

spectralbat
spectralbat

Reputation: 407

Have you considered using NOT IN? (I haven't tested this, so this is theory...)

$projects = Project::whereNotIn('id', $doNotDisplayThisProjectsIds)->get();

Upvotes: 5

Related Questions