Support the ongoing development of Laravel.io →
Input Eloquent Views
Last updated 1 year ago.
0

try

User::all()->with('Articles')->toJSON();
0

Oh sorry my bad, i made it work. Thanks!

However, how to send custom methods from User too?

Last updated 9 years ago.
0

You would first need to get the Collection without the toJSON() and perform your methods, then use toJSON() on your method outputs.

$usersArticles = User::all()->with('Articles');

foreach($usersArticles as $userArticle) {
    echo $userArticle->myCustomUserMethod();
}

or

echo $userArticle->myCustomUserMethod()->toJSON();

if it outputs an object/array.

Last updated 9 years ago.
0

public function ajaxScroll() { $take = Input::get('take'); $skip = Input::get('skip');

	$articles = Article::orderBy('created_at', 'desc')
		->take($take)
		->skip($skip)
		->with('user', 'votes')
		->get()
		->toJson();

	return $articles;
}

How to do that in my case?

Last updated 9 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

filip01 filip01 Joined 2 Jan 2015

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.