2014-10-03 120 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'); 
相關問題