I've been beating myself up with this and can't seem to be able to get my JSON to only display the title and description of the rooms should they be live. I have tried using return $this->hasMany('Room')->select(array('id', 'title', 'description')); but it returns nothing at all for rooms.
Can anyone help? I'm sure this must be very simple to achieve as I understood Laravel Eloquent to be simplistic for this kind of task.
JSON
[
{
id: 1,
building_title: "Drum Castle"
room: [
{
id: 1,
building_id: 7,
title: "Snooker Room",
description: "Full Description",
live: 1
}
]
}
]
Building Model
public function room()
{
return $this->hasMany('Room');
}
Room Model
public function building()
{
return $this->belongsTo('Building', 'building_id');
}
Controller
$buildings = Building::with('room')->get();
Building::with('room')->get();?