【问题标题】:Laravel Ardent is not updatingLaravel Ardent 没有更新
【发布时间】:2014-05-08 12:58:49
【问题描述】:

我正在尝试向 Items 模型中的项目提交更新。但是,当更新方法接收到更新但不会抛出错误时,Ardent 从未真正执行更新:

public function update($id)
{
    $item = Item::findOrFail($id);

    if ($item->save()) {
        return Redirect::back()->with('message', "Item #$id updated!");
    } else {
        return Redirect::back()->withInput()->withErrors($item->errors());
    }
}

我的控制器逻辑有什么问题?

【问题讨论】:

  • 您实际上在哪里更改 $item 的值?
  • 第一次尝试 Ardent。我认为它实际上是自动从 Input 中提取的。没有?
  • 我不认为 Ardent 有那么神奇 ;) github.com/laravelbook/…
  • 我充满希望。 :/ 那么将输入数据传递给 Ardent 进行验证的最简洁的方法是什么?
  • 我自己没有使用过水合,但看起来您只需正确设置这些变量($autoHydrateEntityFromInput 和 $forceEntityHydrationFromInput)即可获得您期望的行为。

标签: laravel laravel-4 ardent


【解决方案1】:

看起来你需要设置这些变量

class Item extends \LaravelBook\Ardent\Ardent {
    // hydrates on new entries' validation
    public $autoHydrateEntityFromInput = true;    
    // hydrates whenever validation is called
    public $forceEntityHydrationFromInput = true; 
}

正确地获得您期望的行为。

来源:https://github.com/laravelbook/ardent#automatically-hydrate-ardent-entities

【讨论】:

    猜你喜欢
    • 2014-04-11
    • 2015-02-13
    • 1970-01-01
    • 1970-01-01
    • 2019-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多