Laravel 4:必须提供价值

时间:2014-10-03 14:41:30

标签: php laravel laravel-4

我在基本的wamp服务器中使用Laravel

我收到错误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.

发件人:C:\ webroot \ okalli \ rest \ vendor \ laravel \ framework \ src \ Illuminate \ Database \ Query \ 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 个答案:

答案 0 :(得分:1)

对于您找到的记录,$content->parent_id似乎为空,当您使用<>运算符时,它将抛出此异常(仅=运算符允许为空)。

确保您从数据库中获得了什么,并且您已正确填充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');