Skip to content

Laravel Prompts ​

Nguồn gốc: Bản dịch từ Laravel Prompts

Giới thiệu (Introduction) ​

Laravel Prompts là thư viện PHP thêm giao diện tương tác đẹp mắt vào command-line application, bao gồm placeholder text, validation và nhiều tính năng browser-like.

Prompts hỗ trợ macOS, Linux và Windows (WSL). Trên Windows ngoài WSL, sẽ fallback về form Symfony Console.

Cài đặt (Installation) ​

Prompts đã được cài sẵn trong Laravel. Nếu cần cài riêng:

bash
composer require laravel/prompts

Các loại Prompts ​

Text ​

Nhập text tự do.

Textarea ​

Nhập text nhiều dòng.

Password ​

Nhập mật khẩu (ẩn input).

Confirm ​

Hỏi Yes/No.

Select ​

Chọn từ danh sách options.

Multiselect ​

Chọn nhiều options.

Suggest ​

Autocomplete khi gõ.

Tìm kiếm và chọn từ danh sách lớn.

Multisearch ​

Tìm kiếm và chọn nhiều items.

Pause ​

Tạm dừng và đợi user nhấn Enter.

Informational Messages ​

  • info() — thông tin
  • warning() — cảnh báo
  • error() — lỗi
  • alert() — thông báo nổi bật

Tables ​

Hiển thị dữ liệu dạng bảng trong terminal.

Spin ​

Spinner animation khi chờ task thực thi.

Progress Bar ​

Thanh tiến trình cho task dài.

Terminal Considerations ​

Minimum Terminal Width ​

Prompts yêu cầu terminal tối thiểu 80 cột.

Unsupported Environments ​

Trên terminal không hỗ trợ, tự động fallback về Symfony Console forms.