我看到laravel有一个例外:
{"error":{"type":"LogicException","message":"Relationship method must return an object of type Illuminate\\Database\\Eloquent\\Relations\\Relation"
奇怪的是,我没有在发生异常的模型中建立任何关系。我只在尝试保存模型(更新)时得到异常。它正在保存,它也会引发异常。
型号(非常基础):
class Release extends Eloquent {
protected $guarded = array('id');
}
控制器:
public function update(){
$field = Input::get('field');
$id = Input::get('id');
$value = Input::get('value');
$update = Release::find($id);
$update->$field = $value;
$return = $update->save;
return Response::json($return);
}
我不确定我在这里想念什么吗?
您需要提供的字段名称,table/model
并且$update->save
缺少()
,应该为$update->save()
,例如:
public function update(){
$field = Input::get('field');
$id = Input::get('id');
$value = Input::get('value');
$update = Release::find($id);
$update->{$field} = $value; // Make sure $field contains the field name
$return = $update->save();
return Response::json($return);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句