Ray Lee | 李宗叡
Learn or Die
Published in
Jun 9, 2024

# Multi-line Text Prompts

[Laravel Prompt] 在 11.3 新增了 textarea feature

也可以針對內容做驗證

<?php
use function Laravel\Prompts\textarea;

$story = textarea(
label: 'Tell me a story.',
placeholder: 'This is a story about...',
required: true,
hint: 'This will be displayed on your profile.'
);

// Validation
$story = textarea(
label: 'Tell me a story.',
validate: fn (string $value) => match (true) {
strlen($value) < 250 => 'The story must be at least 250 characters.',
strlen($value) > 10000 => 'The story must not exceed 10,000 characters.',
default => null
}
);

# New Session hasAny() Method

11.3 新增了 Session::hasAny() method

<?php
// Before
if (session()->has('first_name') || session()->has('last_name')) {
// do something...
}

// Using the new hasAny() method
if (session()->hasAny(['first_name', 'last_name'])) {
// do something...
}

# Context Pull Method

11.3 可以從 Context 當中 remove 特定的 key

<?php
$foo = Context::pull('foo');
$bar = Context::pullHidden('foo');

--

--

Ray Lee | 李宗叡
Learn or Die

It's Ray. I do both backend and frontend, but more focus on backend. I like coding, and would like to see the whole picture of a product.