为什么查询存储库中不可读的条件?

时间:2017-01-27 10:34:18

标签: laravel repository laravel-5.3 laravel-eloquent

我从这里获得了存储库教程:

https://github.com/rinvex/repository

我尝试制作这样的代码:

<?php

namespace App\Repositories;

use App\Models\Favorite;
use Illuminate\Contracts\Container\Container;
use Rinvex\Repository\Repositories\EloquentRepository;
use DB;
Use Log;

class FavoriteRepository extends EloquentRepository
{
    // Instantiate repository object with required data
    public function __construct(Container $container)
    {
        $this->setContainer($container)
             ->setModel(Favorite::class)
             ->setRepositoryId('rinvex.repository.uniqueid');
    }

    public function getFavoriteStore($user_id, $id_store)
    {
        DB::enableQueryLog();

        $query = Self::where('favoritable_id', $id_store)
                         ->where('user_id', $user_id)
                         ->first();

        $queries = DB::getQueryLog();
        foreach($queries as $i=>$query)
        {
            Log::debug("Query $i: " . json_encode($query));
        }

        return $query;
    }
}

我调试查询,结果如下:

  

数组:3 [▼

     

&#34;查询&#34; =&GT; &#34;从favorites限制1&#34;

中选择*      

&#34;绑定&#34; =&GT; []

     

&#34;时间&#34; =&GT; 1.28

     

看起来,没有条件

为什么会这样?

0 个答案:

没有答案