【发布时间】:2020-07-12 02:11:49
【问题描述】:
您好,我创建了一个小的 Laravel getter,如下所示。
public function getYearListAttribute(){
$presentyear = intval($this->created_at->format('Y'));
$myarray[] = array(
'present' => $presentyear,
'past1' => $presentyear-1,
'past2' => $presentyear-2,
'past3' => $presentyear-3
);
return response()->json($myarray);
}
我这样称呼它为 from Blade。
{{$mymodel->yearlist}}
但是我收到了带有标题的响应,而不是只有数组列表。
HTTP/1.0 200 OK Cache-Control: no-cache, private Content-Type: application/json Date: Sun, 12 Jul 2020 02:05:44 GMT [{"present":2020,"past1":2019,"past2":2018,"past3":2017}]
非常感谢您对此提供任何建议或指导,谢谢。
【问题讨论】: