Updating a column giving error in laravel 4

155 views Asked by At

I am trying to update a column named 'is_shared' in laravel but it is giving error.

I tried.

public static function setShared($key, $status = true){
    $input = ScorecardInputMeta::where("key", $key)->first();
    if($input){
       $input->is_shared = $status;
       $input->save;
    }
}//end function

Error: {"error":{"type":"Symfony\Component\Debug\Exception\FatalErrorException","message":"Call to a member function getResults() on boolean","file":"D:\Projects\hbi_private\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php","line":2070}}

1

There are 1 answers

3
Jake Opena On BEST ANSWER

Assuming ScorecardInputMeta is an Eloquent Model, try:

public static function setShared($key, $status = true)
{
    // ->where(column, operator, value)
    $input = ScorecardInputMeta::where('key', '=', $key)->first();

    // check if input is not null or an object
    if ($input) {
        $input->is_shared = $status;
        $input->save(); // changed from $input->save
    }
}