如何在laravel中使用WhereIn与Eloquent?

时间:2016-04-05 04:33:45

标签: php laravel-5 eloquent

我想在Eloquent中使用WhereIn方法,但现在它的功能如下所示

消息:Call to undefined method Illuminate\Database\Query\JoinClause::whereIn()

 Class Notificatin extends Model{

 public function getNotification($user_id)
    {

        $this->_data = self::select('*')
            ->join('user_permission', function($join){
                $join->on('n_user_id','=','user_id')->whereIn('permission_id',array(90,91,92,93));
            })
            ->get();
        if (count($this->_data)) {
            return $this->_data;
        } else {
            return $this->_data;
        }
    }
   }

2 个答案:

答案 0 :(得分:4)

您需要修改<script> function DisplayTooltip(tooltip_text) { fadingTooltip.innerHTML = tooltip_text; tooltip_shown = (tooltip_text != "") ? true : false; if (tooltip_text != "") { // Get tooltip window height tooltip_height = (fadingTooltip.style.pixelHeight) ? fadingTooltip.style.pixelHeight : fadingTooltip.offsetHeight; transparency = 0; ToolTipFading(); } else { clearTimeout(timer_id); fadingTooltip.style.visibility = "hidden"; } } function DisplayTooltip(tooltip_text) { fadingTooltip.innerHTML = tooltip_text; tooltip_shown = (tooltip_text != "") ? true : false; if (tooltip_text != "") { // Get tooltip window height tooltip_height = (fadingTooltip.style.pixelHeight) ? fadingTooltip.style.pixelHeight : fadingTooltip.offsetHeight; transparency = 0; ToolTipFading(); } else { clearTimeout(timer_id); fadingTooltip.style.visibility = "hidden"; } } function AdjustToolTipPosition(e) { if (tooltip_shown) { // Depending on IE/Firefox, find out what object to use to find mouse position var ev; if (e) ev = e; else ev = event; fadingTooltip.style.visibility = "visible"; offset_y = (ev.clientY + tooltip_height - document.body.scrollTop + 30 >= wnd_height) ? -15 - tooltip_height : 20; fadingTooltip.style.left = Math.min(wnd_width - tooltip_width - 10, Math.max(3, ev.clientX + 6)) + document.body.scrollLeft + 'px'; fadingTooltip.style.top = ev.clientY + offset_y + document.body.scrollTop + 'px'; } } function WindowLoading() { fadingTooltip = document.getElementById('fadingTooltip'); // Get tooltip window width tooltip_width = (fadingTooltip.style.pixelWidth) ? fadingTooltip.style.pixelWidth : fadingTooltip.offsetWidth; // Get tooltip window height tooltip_height = (fadingTooltip.style.pixelHeight) ? fadingTooltip.style.pixelHeight : fadingTooltip.offsetHeight; UpdateWindowSize(); } function ToolTipFading() { if (transparency <= 100) { fadingTooltip.style.filter = "alpha(opacity=" + transparency + ")"; fadingTooltip.style.opacity = transparency / 100; transparency += 5; timer_id = setTimeout('ToolTipFading()', 35); } } function UpdateWindowSize() { wnd_height = document.body.clientHeight; wnd_width = document.body.clientWidth; } </script>个查询并将join clouse放在一边:

whereIn

答案 1 :(得分:1)

不使用Joins:

whereIn / whereNotIn / orWhereIn / orWhereNotIn

whereIn方法验证给定数组中是否包含给定列的值:

$users = DB::table('users')
                ->whereNotIn('id', [1, 2, 3])
                ->get();

whereNotIn方法验证给定数组中是否不包含给定列的值:

self.f = GaussianProcess(corr='linear',theta0=1e-2,thetaL=1e-4,thetaU=1e-1)