The laravelEloquentall () method queries the mysqldate field and returns only the year

Source: Internet
Author: User
The attribute of the mysqldate_key field is date. after a model is created using laraveleloquent, the all () method is used. the date_key field returns only the year. I don't know whether the time format of the model needs to be set or what is the problem. please advise. The code is as follows: Model: classRpt_ep_readextendsModel {{...

The attribute of the mysql date_key field is date,
Create a model using laravel eloquent and use the all () method. the date_key field returns only the year.
I don't know whether the time format of the model needs to be set or what is the problem. please advise. The code is as follows:
Model:
Class Rpt_ep_read extends Model
{

//protected $table = 'rpt_ep_read';protected $primaryKey = 'date_key';

}
Controller
Use AppModelsRptdataWebRpt_ep_read;
Class TestController extends Controller {
Public function test (){

 $data = Rpt_ep_read::all();  return $data;

}
}
Return value:


Mysql
CREATE TABLErpt_ep_read(
date_keyDate not null comment 'time ',
cust_numInt (11) not null comment 'users ',
Primary key (date_key)
) ENGINE = InnoDB default charset = utf8 COLLATE = utf8_unicode_ci;

DB: table ()-> get () can return normal results

Reply content:

The attribute of the mysql date_key field is date,
Create a model using laravel eloquent and use the all () method. the date_key field returns only the year.
I don't know whether the time format of the model needs to be set or what is the problem. please advise. The code is as follows:
Model:
Class Rpt_ep_read extends Model
{

//protected $table = 'rpt_ep_read';protected $primaryKey = 'date_key';

}
Controller
Use AppModelsRptdataWebRpt_ep_read;
Class TestController extends Controller {
Public function test (){

 $data = Rpt_ep_read::all();  return $data;

}
}
Return value:


Mysql
CREATE TABLErpt_ep_read(
date_keyDate not null comment 'time ',
cust_numInt (11) not null comment 'users ',
Primary key (date_key)
) ENGINE = InnoDB default charset = utf8 COLLATE = utf8_unicode_ci;

DB: table ()-> get () can return normal results

In yourModelAddpublic $incrementing = false;OtherwiseLaravelThe default primary key is auto-increment and is convertedintReturn

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.