2014-10-03 86 views
1

我使用Laravel的基本WAMP服务器Laravel 4:值必须提供

我已经得到了错误Value must be provided.

这是控制器代码:

public function edit($id) 
{ 
    $query  = DB::table('submenus'); 
    $content  = Content::find($id); 
    $galleries = Gallery::where('parent_id', '<>', $content->parent_id)->lists('parent_id', 'id'); 
    $contents = Content::where('parent_id', '<>', $content->parent_id)->lists('parent_id', 'id'); 
    $this_parent = Submenu::where('id'  , '=' , $content->parent_id)->first(); 

    /*if (!empty($galleries)) 
    { 
     $query->whereNotIn('id', $galleries); 
    } 
    if (!empty($contents)) 
    { 
     $query->whereNotIn('id', $contents); 
    }*/ 

    $submenus = $query->lists('name', 'id'); 

    asort($submenus); 

    $submenus[null] = "Aucun"; 

    $this->layout->content = View::make('contents.edit', array(
     "content" => $content, 
     "submenus" => $submenus, 
     "contents" => $contents, 
     "galleries" => $galleries 
    )); 
} 

和错误消息:

InvalidArgumentException 

Value must be provided. 

From:C:\ webroot \ okalli \ rest \ vendor \ laravel \ framework \ src \ Illumin吃\数据库\查询\ Builder.php

// and keep going. Otherwise, we'll require the operator to be passed in. 
if (func_num_args() == 2) 
{ 
    list($value, $operator) = array($operator, '='); 
} 
elseif ($this->invalidOperatorAndValue($operator, $value)) 
{ 
    throw new \InvalidArgumentException("Value must be provided."); 
} 

我真的不知道是什么问题..

回答

1

似乎$content->parent_id为空备案你发现,当你使用<>操作它会抛出这个异常(null只允许=运算符)。

请确保您从数据库中获得期望值,并且您已正确填充parent_id列。

快速的解决方案是使用三元运算符:

$galleries = Gallery::where('parent_id', '<>', ($content->parent_id) ?: 0)->lists('parent_id', 'id'); 
$contents = Content::where('parent_id', '<>', ($content->parent_id) ?: 0)->lists('parent_id', 'id'); 

代替

$galleries = Gallery::where('parent_id', '<>', $content->parent_id)->lists('parent_id', 'id'); 
$contents = Content::where('parent_id', '<>', $content->parent_id)->lists('parent_id', 'id'); 
相关问题