简体   繁体   中英

Splitting laravel eloquent into a few steps, but the result is always empty

Hi Im trying to split my query into a few steps to make it efficient, but the result is always empty. However, if I use the non-splitted query, it's working perfectly. In my opinion, there's no difference between those two.

        $sma = Pendaftar::bentukSekolah('SMA')->tahun(MyHelper::getCurrentYear());
        $smk = Pendaftar::bentukSekolah('SMK')->tahun(MyHelper::getCurrentYear());

//      return $sma->negeri()->count();  --> it's working

        $smaNegeri = $sma->negeri();
        $smaSwasta = $sma->swasta();

        $smkNegeri = $smk->negeri();
        $smkSwasta = $smk->swasta();

        return $smaNegeri->count(); // --> this one always returns zero

Thank you for your time.

this method, I think, only works on QueryBuilder (DB::table). If you want to use it on eloquent, I found this https://github.com/BKWLD/cloner

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