如何使用laravel 5.1进行形式验证,使单词的第一个字母为大写字母


How can I have the first letter of a word in capital letter using laravel 5.1 for a form validation?

UserFormRequest.php

<?php
namespace App'Http'Requests;
use App'Http'Requests'Request;

class UserForm extends Request
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
       return true;
    }
    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'firstname' => 'required|max:50|alpha',
            'per_address' => 'required',//permanent address
            'temp_address' => 'required',//temporary address
            'occupation' => 'required',
            'gender' => 'required',
            'email' => 'required|email|min:6|max:200|unique:users',            
            'phone' => 'required|numeric|digits_between:8,25',           
            'bloodgroup' => 'required',           
            'date' => 'required',

        ];
    }
}

尝试函数ucwordsucfirst,请记住,您需要首先使用转换为小写文本

ucwords(strtolower($text))

注意:mb_strtlower用于多字节编码,如UTF8。

http://php.net/manual/en/function.ucwords.php

http://php.net/manual/en/function.ucfirst.php

http://php.net/manual/en/function.strtolower.php

http://php.net/manual/en/function.mb-strtolower.php