我在基本的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.");
}
我真的不知道是什么问题。
$content->parent_id
您找到的记录似乎为null,并且当您使用<>
operator时,它将引发此异常(仅允许=
operator使用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');
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句