Peter Pavlov
Peter Pavlov

Reputation: 27

Laravel @ hide in blade view records from SQL if True

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

Answers (1)

user320487
user320487

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

Related Questions