简体   繁体   中英

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

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM