阅读(3707) (5)

Laravel 8 plural {#collection-method}

2021-07-05 09:43:51 更新

plural 方法将单数形式的字符串转换为复数形式。目前该函数仅支持英语:

use IlluminateSupportStr;

$plural = Str::of('car')->plural();

// cars

$plural = Str::of('child')->plural();

// children   

您亦可给该函数提供一个整数作为第二个参数用于检索单数或复数形式:

use IlluminateSupportStr;

$plural = Str::of('child')->plural(2);

// children

$plural = Str::of('child')->plural(1);

// child