Console
Ngoài bảng điều khiển quản trị, Flarum cung cấp một số lệnh console để giúp quản lý diễn đàn của bạn qua thiết bị đầu cuối
Using the console:
sshvào máy chủ nơi lưu trữ cài đặt flarum của bạncdto the folder that contains the fileflarum- Chạy lệnh
php flarum [command]
Lệnh mặc định
list
Liệt kê tất cả các lệnh quản lý có sẵn, cũng như hướng dẫn sử dụng các lệnh quản lý
help
php flarum help [tên_câu_lệnh]
Hiển thị kết quả trợ giúp cho một lệnh nhất định.
Bạn cũng có thể xuất ra trợ giúp ở các định dạng khác bằng cách sử dụng tùy chọn --format:
php flarum help --format=xml list
Để hiển thị danh sách các lệnh có sẵn, vui lòng sử dụng lệnh danh sách.
info
php flarum info
Get information about Flarum's core and installed extensions. Điều này rất hữu ích cho các sự cố gỡ lỗi và nên được chia sẻ khi yêu cầu hỗ trợ.
tinker
php flarum tinker
Opens an interactive PHP shell (a REPL) with your Flarum application fully booted. This lets you inspect and manipulate your forum's data and services directly, without writing a throwaway script or clicking through the admin UI. It is powered by PsySH.
This is primarily a tool for maintainers and extension developers when debugging, inspecting data, or performing one-off data fix-ups.
Flarum's tinker uses the same underlying REPL (PsySH) as Laravel's, but it is not the laravel/tinker package — Flarum does not build on Laravel's full framework. In practice this means:
- There is no
tinker.phpconfig file, and Laravel's facades are not registered. If you reach for one out of habit (e.g.DB::table(...)), the shell will point you to the Flarum equivalent — resolve services through the container instead (resolve(...)or the variables listed below). The$dbvariable is the equivalent of theDBfacade. - Short-name model aliasing only applies to Eloquent models (e.g.
User), and resolves to Flarum's classes such asFlarum\User\User, notApp\Models\User.
tinker gives you unrestricted access to your database and application. There is no undo. A single line can permanently delete data, and because writes go through Eloquent they fire the same events, observers, and cascades as the running application — a ->delete() here behaves exactly as it would in production.
- Take a database backup before making any changes.
- Prefer running read-only inspection first; only run writes when you are certain what they will do.
- Treat it with the same care as running SQL directly against your production database.
Once inside the shell, the following variables and helpers are available to save you typing out fully-qualified class names:
| Available | What it is |
|---|---|
$container | The Flarum application (service container). |
$settings | The settings repository (SettingsRepositoryInterface). |
$db | The database connection. |
$events | The event dispatcher. |
$extensions | The extension manager. |
resolve(...) | Resolve any other binding from the container, e.g. resolve(Flarum\Http\UrlGenerator::class). |
In addition, Eloquent models can be referenced by their short name — User instead of Flarum\User\User. This works for models provided by core and by installed extensions.
Run flarum inside the shell at any time to reprint this list of available variables and helpers, or help for PsySH's own commands.
Examples
Inspect your forum's data:
>>> User::count();
=> 350
>>> User::find(1)->username;
=> "admin"
>>> Discussion::count();
=> 467
Read and change settings:
>>> $settings->get('forum_title');
=> "My Forum"
>>> $settings->set('forum_title', 'My Renamed Forum');
=> null
Check which extensions are enabled:
>>> count($extensions->getEnabledExtensions());
=> 12
>>> $extensions->isEnabled('flarum-tags');
=> true
Run a raw query against the database:
>>> $db->table('users')->where('is_email_confirmed', false)->count();
=> 6
Resolve any service from the container:
>>> resolve(Flarum\Http\UrlGenerator::class)->to('forum')->base();
=> "https://my-forum.example.com"
Type exit (or press Ctrl+D) to leave the shell.