Support the ongoing development of Laravel.io →
Requests Database Eloquent
Last updated 2 years ago.
0

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?

Last updated 2 years ago.
0

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
	);
}
Last updated 2 years ago.
0

Add a foreach() then do an if to add the new entry to the array?

Last updated 2 years ago.
0

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?

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

6S 6s Joined 7 Aug 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.