1
는이 같은 웅변 모델이 있습니다장식 웅변 모델 속성 Laravel 5
<?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()
없이 그냥 웅변 기능을 사용하십시오.
결과 내가 원하는 :
[
{
"title":"NEWS 1",
"desc":"News Description1"
},
{
"title":"NEWS 2",
"desc":"News Description2"
}
]