mysql date_key 字段属性是date,
用laravel eloquent创建模型后 使用all() 方法,date_key 字段只返回年。
不知道是模型时间格式得设置还是什么问题,求指点。代码如下:
模型:
class rpt_ep_read extends model
{
// protected $table = 'rpt_ep_read'; protected $primaryKey = 'date_key';
}
控制器
use AppModelsRptdataWebRpt_ep_read;
class TestController extends Controller {
public function test(){
$data = Rpt_ep_read::all(); return $data;
}
}
返回值:
mysql
CREATE TABLE rpt_ep_read (
date_key date NOT NULL COMMENT '时间',
cust_num int(11) NOT NULL COMMENT '用户数',
PRIMARY KEY (date_key)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
用DB::table()->get()能正常返回
mysql date_key 字段属性是date,
用laravel eloquent创建模型后 使用all() 方法,date_key 字段只返回年。
不知道是模型时间格式得设置还是什么问题,求指点。代码如下:
模型:
class rpt_ep_read extends model
{
// protected $table = 'rpt_ep_read'; protected $primaryKey = 'date_key';
}
控制器
use AppModelsRptdataWebRpt_ep_read;
class TestController extends Controller {
public function test(){
$data = Rpt_ep_read::all(); return $data;
}
}
返回值:
mysql
CREATE TABLE rpt_ep_read (
date_key date NOT NULL COMMENT '时间',
cust_num int(11) NOT NULL COMMENT '用户数',
PRIMARY KEY (date_key)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
用DB::table()->get()能正常返回
在你的Model下面加上public $incrementing = false; 不然Laravel 默认主键是自增的,会转成int返回
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号