laravel学院官方教程链接:https://learnku.com/docs/laravel/5.1/controllers/1043
Artisan 是 Laravel 的命令行接口的名称,它提供了许多用的命令来帮助你开发 Laravel 应用,它由强大的 Symfony Console 组件所驱动。
https://learnku.com/docs/laravel/5.1/migrations/1082
- 查看所有可用命令
php artisan auth:clear-resets
- artisan命令
php artisan clear-compiled // 移除编译好的类文件
php artisan optimize //报错类不存在的时候使用
artisan cache:clear //清除chace
php artisan down //应用进入维护模式
php artisan up //应用离开维护模式进入正常模式
php artisan env // 显示当前环境, 即.env里的APP_ENV
php artisan help // 显示帮助信息
php artisan inspire //显示自定义的一个演示用的artisan
- php artisan migrate //数据迁移
php artisan migrate:install // 在数据库创建一个用以迁移数据的表migrations
php artisan make:migration 待创建的文件名 --create=数据库表名 // 在database/migrations目录中生成一个名为 时间+迁移名.php 的数据迁移文件
php artisan migrate // 把database/magrations目录下的数据迁移表恢复到数据库
//有时候执行数据迁移命令执行后不生效的原因,是数据库migrations迁移记录表已记录了迁移信息,需要收到删除migrations表的记录,或者删除migrations表后重新创建migrations表,
php artisan migrate:refresh //刷新迁移表
// 迁移制定的数据迁移文件
- php artisan tinker // 和应用程序交互
- Psy Shell v0.7.2 (PHP 5.6.27 鈥?cli) by Justin Hileman
- >>> (new Test1)->up(); // Test1 为你的database?marations目录下的数据迁移文件的类名,up()方法会在数据库创建一个数据表
- => null //此时查看数据库已生产数据表
- >>>
php artisan migrate --path=database/migrations/single // 指定文件夹路径迁移数据表
php artisan migrate:refresh //重置并重新执行所有的数据迁移
php artisan migrate:reset // 回滚所有的数据迁移
php artisan migrate:rollback // 回滚最近一次数据迁移
php artisan migrate:status // 显示全部的迁移表
- 优化 laravel 应用 https://learnku.com/articles/2020/ten-laravel-5-program-optimization-techniques
php rtisan config:cache //配置信息缓存
php artisan config:clear 配置信息缓存删除
php artisan route:cache //路由缓存
php artisan route:clear //路由缓存删除
php artisan optimize //类映射加载优化
php artisan optimize --force //常用加载的类合并到一个文件里,通过减少文件的加载,来提高运行效 会生成 bootstrap/cache/compiled.php 和 bootstrap/cache/services.json 两个文件。你可以可以通过修改 config/compile.php 文件来添加要合并的类。在 production 环境中,参数 --force 不需要指定,文件就会自动生成。
//注意:此命令要运行在 php artisan config:cache 后,因为 optimize 命令是根据配置信息(如:config/app.php 文件的 providers 数组)来生成文件的。
php artisan clear-compiled //类映射加载优化删除
php composer dumpautoload //自动加载优化 此命令不止针对于 Laravel 程序,适用于所有使用 composer 来构建的程序。此命令会把 PSR-0 和 PSR-4 转换为一个类映射表,来提高类的加载速度。
config/session.php //使用 Memcached 来存储会话
config/cache.php //使用专业缓存驱动器
数据库请求优化
为数据集书写缓存逻辑
使用即时编译器(JIT),如:HHVM
开启 OpCache
前端资源合并 Elixir
- 缓存 cache
php artisan cache:clear // 刷新应用缓存
php artisan cache:table // 在database/mirations目录为缓存数据库表创建迁移
- 启动开发服务器
php artisan serve //Laravel development server started on http://localhost:8000/
启动REPL shell界面调试应用,在次界面可以使用你的应用的任何类 https://laravelacademy.org/post/4935.html
php artisan tinker // Interact with your application
>>> (new App\Http\Controllers\HomeController())->test() //直接new一个类并执行test()方法
>>> show App\Http\Controllers\HomeController::test; //打印test()方法的源码
>>> show App\Http\Controllers\HomeController //打印类的源码
>>>
- PsySH和tinker功能差不多,但是更强大,在 Laravel 之外使用 PsySH https://learnku.com/articles/7338/understand-laravel-tinker-shell
composer global require psy/psysh:@stable
- 修改应用名称
php artisan app:name 新应用名 //注意命名空间会一起改变
- 刷新过期的密码重置令牌
php artisan auth:clear-resets
数据填充 教程: https://learnku.com/docs/laravel/5.5/seeding/1330
php artisan make:seeder UsersTableSeeder //由框架生成的 seeders 都将被放置在 database/seeds 目录下
composer dump-autoload //在编写了run方法后运行
php artisan db:seed Seed the database with records
event
event:generate Generate the missing events and listeners based on registration
handler
handler:command Create a new command handler class
handler:event Create a new event handler class
key
key:generate Set the application key
make
make:command Create a new command class
make:console Create a new Artisan command
php artisan make:controller 类名 //创建新的资源控制器类 默认在app/Http/Controllers目录下
php artisan make:model ./Models/Log/DecryptLog //这个就是创建一个Decrypt模型文件到app\Models\Log\DecryptLog.php目录下;
php artisan make:event 类名 //创建新的事件类默认在app/Events目录
php artisan make:job 类名 // 创建新的作业类默认在app/Jobs目录
php artisan make:listener 监听类名 --event=\App\Events\事件类名 // 创建新的事件监听类默认在app/Listener目录
//需要打开 app/Providers/EventServiceProvider.php,在 $listen 中添加事件和事件的监听器
php artisan make:middleware //创建中间件 需要先安装composer create-project laravel/laravel LaravelMiddleware --prefer-dist
make:migration Create a new migration file
make:model Create a new Eloquent model class
make:policy Create a new policy class
make:provider Create a new service provider class
make:request Create a new form request class
make:seeder Create a new seeder class
make:test Create a new test class
migrate
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:subscribe Subscribe a URL to an Iron.io push queue
queue:table Create a migration for the queue jobs database table
queue:work Process the next job on a queue
- 路由
php artisan route:list //显示所有已注册路由
- schedule
php artisan schedule:run // 运行计划的命令
- session
php artisan session:table //创建session表
vendor:publish Publish any publishable assets from vendor packages
- view
php artisan view:clear 清楚全部编译好的视图文件