【问题标题】:Laravel Ardent not saving model when using updateUniques()使用 updateUniques() 时 Laravel Ardent 不保存模型
【发布时间】:2014-01-27 01:20:24
【问题描述】:

我正在为我的管理面板做用户编辑工具。我在代码中使用了 updateUniques(),正如 Ardent 在模型中有“唯一”规则时所推荐的那样。

当我这样做时,它没有问题通过,但模型没有改变。

我的代码:

$user = User::findOrFail($id);

if ($user->exists)
{
    $user::$rules['password'] = (Input::get('password')) ? 'required|confirmed' : '';
    $user::$rules['password_confirmation'] = (Input::get('password')) ? 'required' : '';
}

if ($user->updateUniques())
{
    Session::flash('successes', array_merge((array) Session::get('successes'), ['Pomyślnie zmieniono użytkownika']));
    return Redirect::route('users.show', ['users'   =>  $user->id]);
}
else
{
    return Redirect::route('users.edit', ['users'   =>  $user->id])
    ->withErrors($user->errors())
    ->withInput(Input::except('password'));
}

【问题讨论】:

    标签: php laravel-4 ardent


    【解决方案1】:

    在调试它时,我注意到它并没有用新数据对模型进行水合。经过一番谷歌搜索,我想出了一个解决方案。

    我只需要在我的模型中添加以下内容:

    public $forceEntityHydrationFromInput = true;
    public $autoPurgeRedundantAttributes = true;
    

    【讨论】:

      猜你喜欢
      • 2014-02-14
      • 2014-01-22
      • 1970-01-01
      • 2014-01-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-23
      相关资源
      最近更新 更多