1

I have tables festivals, addressess and locations. A festival has one address and a address has one location. Now I want to get json from these 3 tables with laravel. At the moment I get festivals and addresses. How to retrieve the 3th table locations?

public function json()
        {
            $festival = Festival::with('address')->get();

            return Response::json(array('festivals' => $festival))->setCallback(Input::get('callback'));

        }

2 Answers 2

2

You can eager load nested relationships:

$festival = Festival::with('address.location')->get();
Sign up to request clarification or add additional context in comments.

Comments

0

You can also get relationships via eager loading using comma separated values in the with() method, like so:

$festivals = Festival::with('address', 'address.location')->get();

Hope this helps.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.