Reputation: 27
I cannot understand, how to hide/do not show records from SQL if the status of one or more is XXX
Example:
I have SQL table called - projects, and one project has status - CLOSED.
My blade view will display this project together with projects who has status - OPEN
How I can hide if project is Closed?
THankx
Upvotes: 0
Views: 319
Reputation:
If you want to exclude all projects with a status of closed, you can return the filtered collection in your controller:
$projects = Project::where('status', '<>', 'closed')->get();
Better yet, create a local scope on the Project
model:
public function scopeOpen($query) {
return $query->where('status', 'open');
}
And then use it later:
$projects = Project::open();
Upvotes: 1