Oihana PHP System

rules.php

Table of Contents

Functions

rules()  : string
Generates a concatenated validation rules string from multiple rules.

Functions

rules()

Generates a concatenated validation rules string from multiple rules.

rules(string|array<string|int, mixed> ...$rules) : string

This helper allows you to pass a list of rules as strings or arrays and concatenates them using the pipe (|) character, which is commonly used in validation libraries (like Somnambulist Validation or Laravel) to separate multiple validation constraints.

Parameters
$rules : string|array<string|int, mixed>

One or more rules to combine.

Tags
example
use function oihana\validations\rules\helpers\rules;

// Pass rules as an array
$rules = rules([ 'required', 'min:5', 'max:10' ]);
// Returns: 'required|min:5|max:10'

// Pass rules as separate arguments
$rules = rules('required', 'min:5', 'max:10');
// Returns: 'required|min:5|max:10'

// Mixed usage
$rules = rules('required', ['min:5', 'max:10']);
// Returns: 'required|min:5|max:10'
see
compile()

Helper used internally to join rules.

Return values
string

        
On this page

Search results