【问题标题】:Laravel/Ardent: SQLSTATE[HY093]: Invalid parameter number: mixed named and positional parametersLaravel/Ardent:SQLSTATE[HY093]:无效参数号:混合命名参数和位置参数
【发布时间】:2014-03-05 17:36:09
【问题描述】:

我正在尝试使用 Ardent 的 validate() 方法验证用户,但我总是收到带有以下额外信息的 HY093 错误

(SQL: select count(*) as aggregate from:userswhereemail= my.email@gmail.com)

我使用 Sentry2 进行“用户”表数据库迁移。

我的用户模型设置如下:

/**
* Validation Rules for ARDENT here
*/    
public static $rules = [
    'first_name'            => 'required',
    'last_name'             => 'required',
    'email'                 => 'required|email|unique::users',
    'password'              => 'required|between:8,32|confirmed',
    'password_confirmation' => 'required|between:8,32',
];

/**
 * The attributes that can be added to a new User using $user->fill()
 *
 * @var array
 */
protected $fillable = [
    'first_name', 
    'last_name', 
    'email', 
    'password', 
    'password_confirmation'
];

/**
 * Automatically removes _confirmation attributes
 *
 * @var boolean
 */
public $autoPurgeRedundantAttributes = true;

从一个表单中,我有 POST 数据,其中包括 ['email'、'first_name'、'last_name'、'password'、'password_confirmation] 以及它们各自的值,这些值将转到我的 UserController 中的以下函数:

public function signup() {
    // Create a new User object
    $user = new User();

    // Populate attributes with information described in User->fillable
    $user->fill( Input::all() );

    // Check if info is valid using Ardent's validate() method
    if ( $user->validate() ) {
    ....
    ....
    ....

我的代码总是在if ( $user->validate() ) 行上失败。谁能帮我解释一下这种情况?

【问题讨论】:

    标签: php mysql laravel ardent


    【解决方案1】:

    问题是这一行

    'email' => 'required|email|unique::users'
    

    应该是

    'email' => 'required|email|unique:users'
    

    根据The Laravel Docs

    【讨论】:

      猜你喜欢
      • 2018-07-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-09
      • 1970-01-01
      • 2012-06-13
      • 1970-01-01
      相关资源
      最近更新 更多