douqu2712 2016-03-09 21:22
浏览 313
已采纳

Laravel通过字段名称改变了eloquent更改属性

My model structure after model -> find($id);

  protected 'attributes' => 
    array (size=35)
      'id' => string '1234134' (length=6)
      'case' => string '123123' (length=7)

I want to update this model like this

foreach($input as $key => $value){
                var_dump($key);
                $case->($key)= $value;
            }
    $case -> save();

I tried like this but doesn't work

$reflection = new \ReflectionClass($case);  
    foreach($input as $key => $value){
                var_dump($key);
                $reflection->"$ke"y;
            }
  • 写回答

4条回答 默认 最新

  • dtf0925 2016-03-09 23:57
    关注

    if this is a laravel eloquent model, you could utilize the use of the fill method.

    $case->fill($input);
    $case->save();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?