On the problem of data query preloading in tp5

   CompanyModel::with(["user"=>function($query) use($search){
        $query->field("user_id,user_name,company_id")->where($search["ucon"]);
    }])->field("id,name,title,type,utm_tag,status")->where($search["con"])->paginate(15);
    
    

how to write such a code: when the closure condition is not satisfied, the data cannot be found;
now, when the closure condition is not satisfied, all the data in the companymodel table will come out.

Php
Feb.16,2022

you can use the when method. You can also call the load method after the query is completed without with.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b39bbd-34584.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b39bbd-34584.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?