Laravel eloquent All () method queries the MySQL date field only returns the year

Source: Internet
Author: User

MySQL Date_key field property is date,
Using the All () method after creating the model with Laravel eloquent, the Date_key field returns only the year.
Do not know whether the model time format to set or what the problem, seek guidance. 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 TABLE rpt_ep_read (
date_keyDate not NULL COMMENT ' time ',
cust_numInt (one) not NULL COMMENT ' number of users ',
PRIMARY KEY ( date_key )
) Engine=innodb DEFAULT Charset=utf8 collate=utf8_unicode_ci;

Use Db::table ()->get () to return normally

Reply content:

MySQL Date_key field property is date,
Using the All () method after creating the model with Laravel eloquent, the Date_key field returns only the year.
Do not know whether the model time format to set or what the problem, seek guidance. 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 TABLE rpt_ep_read (
date_keyDate not NULL COMMENT ' time ',
cust_numInt (one) not NULL COMMENT ' number of users ',
PRIMARY KEY ( date_key )
) Engine=innodb DEFAULT Charset=utf8 collate=utf8_unicode_ci;

Use Db::table ()->get () to return normally

Add it to your Model bottom public $incrementing = false; , or the Laravel default primary key is self-increment, and it turns into a int return

  • 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.