本篇文章给大家带来的内容是关于laravel框架中超实用的功能介绍,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。
让lumen的dd() dump()像laravel一样优雅
|
1
|
composer require symfony/var-dumper
|
获取执行的sql语句
可查看sql where参数等
|
1
2
3
4
5
6
7
8
9
10
|
public function index()
{
DB::connection()->enableQueryLog();
DB::table('posts')->paginate(5);
$queries = DB::getQueryLog();
dd($queries);
}
|
只能查看简单的sql不能看到传入的参数
|
1
|
DB::table('posts')->toSql();
|
查询sql记录
如果,你想要将日志文件保存在 storage/logs 目录中。需要更新: app/Providers/AppServiceProvider.php 里的 boot() 函数
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use DB;
use Log;
class AppServiceProvider extends ServiceProvider
{
public function boot()
{
DB::listen(function ($query) {
Log::info(
$query->sql,
$query->bindings,
$query->time
);
});
}
public function register()
{
}
}
|
![]()
![]()
![]()
链接:https://pan.baidu.com/s/1v5gm7n0L7TGyejCmQrMh2g 提取码:x2p5
免费分享,但是X度限制严重,如若链接失效点击链接或搜索加群 群号518475424。
Laravel 如何在模型事件中获取某字段修改前的值
|
1
2
3
4
5
6
7
8
|
Issue::saving(function(Issue $issue){
if ($issue->isDirty('title')) {
$user = Auth::user()->username;
$oldTitle = $issue->getOriginal('title');
$newTitle = $issue->title;
ActionLog::log("$user 把标题 $oldTitle 修改为 $newTitle");
}
});
|
以上就是laravel框架中超实用的功能介绍的详细内容