【发布时间】:2017-09-19 14:37:55
【问题描述】:
我有这样一个雄辩的模型:
<?php
namespace News\Model;
class News extends Model
{
public $fillable = [
'title',
'desc'
];
public function getUpperTitle(){
return strtoupper($this->title);
}
}
并拥有这样的控制器:
use News;
class NewsController extends Controller
{
public function index()
{
return News::all();
}
}
现在我想返回所有标题大写的新闻(标题装饰)而不调用getUpperTitle(),只使用 eloquent 函数。
我想要的结果:
[
{
"title":"NEWS 1",
"desc":"News Description1"
},
{
"title":"NEWS 2",
"desc":"News Description2"
}
]
【问题讨论】:
标签: php laravel laravel-5 eloquent