Search code examples
phpjsonlaravellaravel-4jsonp

Laravel 4 : getting json from database tables


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'));

        }

Solution

  • You can eager load nested relationships:

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