我从这里获得了存储库教程:
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
看起来,没有条件
为什么会这样?