lumen artisan支持的命令列表
使用兩種方式創(chuàng)建項(xiàng)目
1. 通過(guò) Lumen 安裝器
創(chuàng)建項(xiàng)目
composer global require "laravel/lumen-installer"
將 ~/.composer/vendor/bin 路徑加到環(huán)境變量中的 PATH 脯燃,只有這樣系統(tǒng)才能找到 lumen 的可執(zhí)行文件霹疫。
lumen new blog
2. 通過(guò) Composer Create-Project 命令安裝
composer create-project --prefer-dist laravel/lumen blog
運(yùn)行程序
php -S localhost:8000 -t public
查看支持的文件列表
php artisan list
art list
Laravel Framework Lumen (5.7.1) (Laravel Components 5.7.*)
Usage:
command [options] [arguments]
Options:
-h, --help Display this help message
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
--env[=ENV] The environment the command should run under
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
Available commands:
help Displays help for a command
list Lists commands
migrate Run the database migrations
auth
auth:clear-resets Flush expired password reset tokens
cache
cache:clear Flush the application cache
cache:forget Remove an item from the cache
cache:table Create a migration for the cache database table
db
db:seed Seed the database with records
make
make:migration Create a new migration file
make:seeder Create a new seeder class
migrate
migrate:fresh Drop all tables and re-run all migrations
migrate:install Create the migration repository
migrate:refresh Reset and re-run all migrations
migrate:reset Rollback all database migrations
migrate:rollback Rollback the last database migration
migrate:status Show the status of each migration
queue
queue:failed List all of the failed queue jobs
queue:failed-table Create a migration for the failed queue jobs database table
queue:flush Flush all of the failed queue jobs
queue:forget Delete a failed queue job
queue:listen Listen to a given queue
queue:restart Restart queue worker daemons after their current job
queue:retry Retry a failed queue job
queue:table Create a migration for the queue jobs database table
queue:work Start processing jobs on the queue as a daemon
schedule
schedule:finish Handle the completion of a scheduled command
schedule:run Run the scheduled commands
ref:
https://laravel-china.org/docs/lumen/5.6/install/1924
帶參數(shù)的路由和laravel不一樣了抛人。注意這里的變化
$router->get('user/{id}', function ($id) {
return 'User '.$id;
});
$router->get('posts/{postId}/comments/{commentId}', function ($postId, $commentId) {
//
});
$router->get('user/{id}', function ($id) {
return 'User '.$id;
});
路由組
中間件
$router->group(['middleware' => 'auth'], function () use ($router) {
$router->get('/', function () {
// 使用 Auth 中間件
});
$router->get('user/profile', function () {
// 使用 Auth 中間件
});
});
命名空間
指定相同的 PHP 命名空間給控制器群組局冰∥是裕可以使用 namespace 參數(shù)來(lái)指定群組內(nèi)所有控制器的命名空間:
$router->group(['namespace' => 'Admin'], function() use ($router)
{
// 使用 "App\Http\Controllers\Admin" 命名空間...
$router->group(['namespace' => 'User'], function() use ($router) {
// 使用 "App\Http\Controllers\Admin\User" 命名空間...
});
});
路由前綴
通過(guò)路由群組數(shù)組屬性中的 prefix桥状,在路由群組內(nèi)為每個(gè)路由指定的 URI 加上前綴雇初。例如,你可能想要在路由群組中將所有的路由 URI 加上前綴 admin:
$router->group(['prefix' => 'admin'], function () use ($router) {
$router->get('users', function () {
// 匹配 "/admin/users" URL
});
});