How are you currently returning the data? For example, an Eloquent model, an array, a string you're manually encoding with json_encode(), a new Response instance?
Thanks. Currently I use the default Response instance :
public function index()
{
$messages = Message::where('from', Auth::user()->id)
->orWhere('to', Auth::user()->id)
->get();
return Response::json(
array(
'messages' => $messages->toArray()
),
200
);
}
Add a foreach() then do an if to add the new entry to the array?
Inside the message model add the following:
protected $appends = array('is_sent');
public function getIsSentAttribute()
{
return $this->from == Auth::user()->id ? 1 : 0;
}
What is the penfriend attribute?
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community