<?php
class MenuType extends Eloquent {
protected $fillable = array('name');
function category() {
return $this->hasMany('Category');
}
}
class Category extends Eloquent {
protected $fillable = array('name','maxitems', 'menutype_id');
function menutype() {
return $this->belongsTo('MenuType');
}
}
/*
* When run this, i want my object looks like this:
*
{
id: "1",
category_name: "Update Category56945",
menutype_name: 'some name',
menutype: {
....
}
}
*/
$cats = Category::with(['menutype', 'menutype.name as menutype_name'])->get();
// get error
// Call to undefined method Illuminate\Database\Query\Builder::name()