laravel: 调试打印sql
一,代码:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
class ReadLogModel extends Model
{
use HasFactory;
//定义关联的数据表
protected $table = 'sms_log';
//定义主键
protected $primaryKey = 'log_id';
// 时间字段是否自动管理(created_at 和 updated_at字段)
public $timestamps = false;
// 下面即是允许入库的字段,数组形式,例如:name age sex三个字段允许入库
protected $fillable = ['*'];
//添加一条记录
public function addOne($row) {
DB::enableQueryLog(); //使支持查询日志
$model = $this->create($row);
print_r($model.":<br/>");
$id = $model->log_id;
dd(DB::getQueryLog()); //打印出来
return $id;
}
}