laravel 常用命令

发布时间:2023-10-11 15:55:18 浏览次数:101

1. 创建数据库迁移文件,使用命令行

php artisan make:migration create_users_table

2. 在数据迁移文件中添加所需要的字段

database/migrations/..

3. 生成控制器

php artisan make:controller UserController 
生成资源控制器
php artisan make:controller UserController --resource

4. 生成模型

php artisan make:model Models/User

5. 生成模型并创建数据库迁移文件

php artisan make:model Models/Article -m

6. 模型类创建一个模型工厂:

php artisan make:factory ArticleFactory --model=Article

7. 生成数据库填充文件

php artisan make:seeder UsersTableSeeder

8. 通过命令填充数据

php artisan db:seed
php artisan db:seed --class=UsersTableSeeder

9. 回滚并重新运行所有迁移

 php artisan migrate:refresh --seed

10. 复制.env.example 文件生成.env配置文件

cp .env.example .env

11. 生成中间件

 php artisan make:middlware CheckEmail

12. 生成APP_KEY

php artsian key:generate

13. 生成factory填充假数据

art make:factory ArticleFactory

14. 生成监听事件

php artisan event:generate

15. 生成一条artisan命令

php artisan make:command HelloMessage --command=hello:message


最新文章