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()能正常返回
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
在你的
Model下面加上public $incrementing = false;不然Laravel默认主键是自增的,会转成int返回