1.创建laravel项目
先添加国内镜像
composer config -g repo.packagist composer https://packagist.phpcomposer.com
进到项目目录执行如下命令
composer create-project laravel/laravel --prefer-dist obj_laravel
2.php启动laravel站点
php -S localhost:80 -t obj_laravel/public
相关操作命令
#创建控制器
php artisan make:controller MyController
php artisan make:controller PhotoController --resource
#显示路由
php artisan route:list
#生成模型
php artisan make:model User
#数据迁移
php artisan make:migration create_users_table
#运行迁移
php artisan migrate
#数据填充
php artisan make:seeder UserTableSeeder
#运行填充器
php artisan db:seedphp artisan db:seed --class=UserTableSeeder
#回滚并重新运行迁移
php artisan migrate:refresh --seed
Debugbar
1.使用compser引入package
composer require barryvdh/laravel-debugbar
2.config/app.php的providers中添加注册服务
#line:124~160左右
Barryvdh\Debugbar\ServiceProvider::class,
3.门面(可选)
#config/app.php中添加如下门面别名到 aliases数组:
'Debugbar' => Barryvdh\Debugbar\Facade::class,
#然后运行如下 Artisan 命令将该扩展包的配置文件拷贝到 config目录下:
php artisan vendor:publish
如果配置文件中 debug设置为 true的话,Debugbar 分析器默认是启的,如果你想要关闭该分析器,在配置文件 config/debugbar.php中设置 enab为 false即可。
使用 Debugbar 门面添加 PSR-3 级别消息:
Debugbar::info($object);Debugbar::error('Error!');
Debugbar::warning('Watch out…');
Debugbar::addMessage('Another message', 'mylabel');
设置开始/中止时间:
Debugbar::startMeasure('render','Time for rendering');
Debugbar::stopMeasure('render');
Debugbar::addMeasure('now', LARAVEL_START, microtime(true));
Debugbar::measure('My long operation', function() { // Do something…});
记录异常:
try {
throw new Exception('foobar');
} catch (Exception $e) {
Debugbar::addException($e);
}
使用辅助函数实现上述调用:
// All arguments will be dumped as a debug message
debug($var1, $someString, $intValue, $object);
start_measure('render','Time for rendering');
stop_measure('render');
add_measure('now', LARAVEL_START, microtime(true));
measure('My long operation', function() {
// Do something…
});
如果想要添加自己的数据收集器(DataCollector),可以通过容器或门面实现:
Debugbar::addCollector(new DebugBar\DataCollector\MessagesCollector('my_messages'));
或者通过 App 容器:
$debugbar = App::make('debugbar');
$debugbar->addCollector(new DebugBar\DataCollector\MessagesCollector('my_messages'));
默认情况下,Debugbar 被注入到 </body>之前。如果你想要自己注入 Debugbar,在其配置文件中设置 inject为 false然后使用渲染器自己渲染:
$renderer = Debugbar::getJavascriptRenderer();
注意:使用自动注入的话将会禁止显示 Request 信息,因为在响应之后才会添加该信息。你可以通过在配置文件中添加 default_request数据收集器作为替换方案。
如果你想要在运行时开启/关闭 Debugbar,可以通过如下方式:
\Debugbar::enable();\Debugbar::disable();