CrunchyArtie
CrunchyArtie

Reputation: 427

Laravel 4 : Value must be provided

I use Laravel in a basic wamp server

I've got the error Value must be provided.

this is the controller code :

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
    ));
}

And the error message :

InvalidArgumentException 

Value must be provided.

From: 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.");
}

I really don't know what is the problem..

Upvotes: 1

Views: 2122

Answers (1)

Marcin Nabiałek
Marcin Nabiałek

Reputation: 111839

It seems that $content->parent_id is null for the record you find and when you use <> operator it will throw this exception (null is allowed only for = operator).

Make sure you get from database what expect and you have parent_id column filled properly.

Quick solution would be using ternary operator:

$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');

instead of

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

Upvotes: 1

Related Questions