0

idLaravel ドキュメント、API ドキュメント、およびソース コードを調べて、次の一意のルールの 4 番目のパラメーターが何のためにあるのかを誰かが知っているかどうか疑問に思っています。

'email' => 'unique:users,email_address,NULL,id,account_id,1'

このルールについての私の現在の理解は次のとおりです。

  • users- この表を見て
  • email_address- この列に対するチェック
  • NULL- 無視する主キー/ID 値を指定できる場所ですが、気にしていないので、このパラメーターは基本的に無視されます
  • id-わからない
  • account_id- 追加の where 句、これは列名です
  • 1- account_idwhere 句の値

ドキュメント: http://laravel.com/docs/4.2/validation

次の行の関数にある一意のルール検証を実行する\Illuminate\Validation\Validator関数:validateUnique($attribute, $value, $parameters)949

/**
 * Validate the uniqueness of an attribute value on a given database table.
 *
 * If a database column is not specified, the attribute will be used.
 *
 * @param  string  $attribute
 * @param  mixed   $value
 * @param  array   $parameters
 * @return bool
 */
protected function validateUnique($attribute, $value, $parameters)
{
    $this->requireParameterCount(1, $parameters, 'unique');

    $table = $parameters[0];

    // The second parameter position holds the name of the column that needs to
    // be verified as unique. If this parameter isn't specified we will just
    // assume that this column to be verified shares the attribute's name.
    $column = isset($parameters[1]) ? $parameters[1] : $attribute;

    list($idColumn, $id) = array(null, null);

    if (isset($parameters[2]))
    {
        list($idColumn, $id) = $this->getUniqueIds($parameters);

        if (strtolower($id) == 'null') $id = null;
    }

    // The presence verifier is responsible for counting rows within this store
    // mechanism which might be a relational database or any other permanent
    // data store like Redis, etc. We will use it to determine uniqueness.
    $verifier = $this->getPresenceVerifier();

    $extra = $this->getUniqueExtra($parameters);

    return $verifier->getCount(

        $table, $column, $value, $id, $idColumn, $extra

    ) == 0;
}

乾杯

4

3 に答える 3

2
  • $ARG1 - このテーブルを調べる
  • $ARG2 - この列に対するチェック。デフォルトは検証キー (例: 電子メール)
  • $ARG3 - 追加の WHERE NOT 値。
  • $ARG4 - 追加の WHERE NOT フィールド。デフォルトは主キー
  • $ARG5 - 追加の WHERE フィールド 1 - 追加の WHERE 値。
于 2015-07-14T14:50:37.177 に答える