src/Requests/CommentRequest.php
/**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
Get the validation rules that apply to the request.
@return array
Get the validation rules that apply to the request . @return array
public function rules(): array
    {
        $return = [
            'comment'        => ['required', 'string', 'min:3', 'max:1000'],
            'author_name'    => ['string', 'min:1', 'max:50'],
            'author_email'   => ['string', 'nullable', 'min:1', 'max:254', 'email'],
            'author_website' => ['string', 'nullable', 'min:'.strlen('http://a.b'), 'max:175', 'active_url'],
        ];
        $return['author_name'][] = Auth::check() && config('blogetc.comments.save_user_id_if_logged_in', true)
            ? 'nullable'
            : 'required';
        if (config('blogetc.captcha.captcha_enabled')) {
            $captcha_class = config('blogetc.captcha.captcha_type');
            $captcha = new $captcha_class();
            $return[$captcha->captchaFieldName()] = $captcha->rules();
        }
        if (config('blogetc.comments.rules') && is_callable(config('blogetc.comments.rules'))) {
            $function = config('blogetc.comments.rules');
            $return = $function($return);
        }
        if (config('blogetc.comments.require_author_email')) {
            $return['author_email'][] = 'required';
        }
        return $return;
    }
public function rules ( ) : array { $ return = [ 'comment' => [ 'required' , 'string' , 'min:3' , 'max:1000' ] , 'author_name' => [ 'string' , 'min:1' , 'max:50' ] , 'author_email' => [ 'string' , 'nullable' , 'min:1' , 'max:254' , 'email' ] , 'author_website' => [ 'string' , 'nullable' , 'min:' . strlen ( 'http://a.b' ) , 'max:175' , 'active_url' ] , ] ; $ return [ 'author_name' ] [ ] = Auth :: check ( ) && config ( 'blogetc.comments.save_user_id_if_logged_in' , true ) ? 'nullable' : 'required' ; if ( config ( 'blogetc.captcha.captcha_enabled' ) ) { $ captcha_class = config ( 'blogetc.captcha.captcha_type' ) ; $ captcha = new $ captcha_class ( ) ; $ return [ $ captcha -> captchaFieldName ( ) ] = $ captcha -> rules ( ) ; } if ( config ( 'blogetc.comments.rules' ) && is_callable ( config ( 'blogetc.comments.rules' ) ) ) { $ function = config ( 'blogetc.comments.rules' ) ; $ return = $ function ( $ return ) ; } if ( config ( 'blogetc.comments.require_author_email' ) ) { $ return [ 'author_email' ] [ ] = 'required' ; } return $ return ; }
Get the validation rules that apply to the request.
Get the validation rules that apply to the request .
// basic rules // Do we need author name?
 // If logged in and save_user_id_if_logged_in is true then it is not required. Otherwise it is required. // Is captcha enabled? If so, get the rules from its class. /** @var string $captcha_class */ /** @var CaptchaInterface $captcha */ // in case you need to implement something custom, you can use this... /** @var callable $function */