[李景山php]每天laravel-20161008|Validator.php-8

    /**
     * Validate an attribute is contained within a list of values.
     *
     * @param  string  $attribute
     * @param  mixed   $value
     * @param  array   $parameters
     * @return bool
     */
    protected function validateIn($attribute, $value, $parameters)
    {
        if (is_array($value) && $this->hasRule($attribute, 'Array')) {
            return count(array_diff($value, $parameters)) == 0;
        }// if it is value and this get the count

        return ! is_array($value) && in_array((string) $value, $parameters);
    }//validate an attribute is contained within a list of values
    // i like this two way , just return this result

    /**
     * Validate an attribute is not contained within a list of values.
     *
     * @param  string  $attribute
     * @param  mixed   $value
     * @param  array   $parameters
     * @return bool
     */
    protected function validateNotIn($attribute, $value, $parameters)
    {
        return ! $this->validateIn($attribute, $value, $parameters);// return a wrap function
    }//validate an attribute is not contained within a list of values

    /**
     * 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
     */
    // validate the uniqueness of an attribute value on a given database table.
    // if a database column is not specified, the attribute will be used.
    protected function validateUnique($attribute, $value, $parameters)
    {
        $this->requireParameterCount(1, $parameters, 'unique');//get this function

        list($connection, $table) = $this->parseTable($parameters[0]);// list some method

        // 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;
        // 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.

        list($idColumn, $id) = [null, null];// init this parameter

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

            if (strtolower($id) == 'null') {
                $id = null;
            }// set the number
        }

        // 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();//get Presence Verifier

        $verifier->setConnection($connection);// set Connection

        $extra = $this->getUniqueExtra($parameters);//get Unique Extra

        return $verifier->getCount(

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

        ) == 0;// get Count
    }// so powerfull

    /**
     * Parse the connection / table for the unique / exists rules.
     *
     * @param  string  $table
     * @return array
     */
    protected function parseTable($table)
    {
        return Str::contains($table, '.') ? explode('.', $table, 2) : [null, $table];
    }//Parse the connection table for the unique and exists rules.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值