php 查询方法all,laravel Eloquent all()方法查询mysql date字段只返回年

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;

}

}

返回值:

bVGcxW?w=394&h=247

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;

bVGcyM?w=242&h=239

用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;

}

}

返回值:

bVGcxW?w=394&h=247

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;

bVGcyM?w=242&h=239

用DB::table()->get()能正常返回

在你的Model下面加上public $incrementing = false; 不然Laravel 默认主键是自增的,会转成int返回

本文原创发布php中文网,转载请注明出处,感谢您的尊重!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值