laravel Eloquent all() method queries the mysql date field and only returns the year

WBOY
Release: 2023-03-01 15:58:01
Original
1331 people have browsed it

Mysql date_key field attribute is date,
After creating the model with laravel eloquent and using the all() method, the date_key field only returns the year.
I don’t know if it’s the model time format setting or something else, please give me some advice. The code is as follows:
Model:
class Rpt_ep_read extends Model
{

// protected $table = 'rpt_ep_read'; protected $primaryKey = 'date_key';
Copy after login
Copy after login

}
Controller
use AppModelsRptdataWebRpt_ep_read;
class TestController extends Controller {
public function test(){

 $data = Rpt_ep_read::all(); return $data;
Copy after login
Copy after login

}
}
Return value:

laravel Eloquent all() method queries the mysql date field and only returns the year
mysql
CREATE TABLErpt_ep_read(
date_keydate NOT NULL COMMENT 'time',
cust_numint(11) NOT NULL COMMENT 'number of users',
PRIMARY KEY (date_key)
) ENGINE =InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

laravel Eloquent all() method queries the mysql date field and only returns the year

Using DB::table()->get() can return normally

Reply content:

Mysql date_key field attribute is date,
After creating the model with laravel eloquent and using the all() method, the date_key field only returns the year.
I don’t know if it’s the model time format setting or something else, please give me some advice. The code is as follows:
Model:
class Rpt_ep_read extends Model
{

// protected $table = 'rpt_ep_read'; protected $primaryKey = 'date_key';
Copy after login
Copy after login

}
Controller
use AppModelsRptdataWebRpt_ep_read;
class TestController extends Controller {
public function test(){

 $data = Rpt_ep_read::all(); return $data;
Copy after login
Copy after login

}
}
Return value:

laravel Eloquent all() method queries the mysql date field and only returns the year
mysql
CREATE TABLErpt_ep_read(
date_keydate NOT NULL COMMENT 'time',
cust_numint(11) NOT NULL COMMENT 'number of users',
PRIMARY KEY (date_key)
) ENGINE =InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

laravel Eloquent all() method queries the mysql date field and only returns the year

Using DB::table()->get() can return normally

Addpublic $incrementing = false;below yourModel, otherwiseLaravel’s default primary key is auto-incremented and will be converted tointand returned

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!