简体   繁体   中英

Laravel - Query to mysql DB

I am new to Laravel. I have a existing and working query that allow me to get all the item present in my Mysql Table. File --> ProductRepostitory.php

Public function getAll(){
        $data = Product::paginate(10);
        if(empty($data)){
            return false;
        }else{
            return $data;
        }
    }

In that table I have a column named PR_ACTIF --> 1 or 0. I would like to display in the query only PR_ACTIF = 1 Thanks for you help!

Try this

...
Public function getAll(){
    $data = Product::where('PR_ACTIF', 1)->paginate(10);
    if(empty($data)){
        return false;
    }else{
        return $data;
    }
}
...

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