本篇文章給大家帶來的內容是關于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); //要查看的sql
$queries = DB::getQueryLog(); // 獲取查詢日志
dd($queries); // 即可查看執行的sql,執行的時間,傳入的引數等等
}
|
只能查看簡單的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
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
//
// 新增代碼
DB::listen(function ($query) {
Log::info(
$query->sql,
$query->bindings,
$query->time
);
});
}
/**
* Register any application services.
*
* @return void
*/
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框架中超實用的功能介紹的詳細內容
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/124132.html
標籤:PHP
上一篇:laravel框架的中間件middleware的詳解
下一篇:Laravel服務容器的系結與決議