Level 6
Found the solution. Needed to change the controller return to:
return response()->json($events)->getContent();
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have a simple API Route as such in my routes/api.php:
Route::get('events', function () {
return Event::all();
});
And when I hit that route, I get json of exactly the event entities:
[{"id":1,"name":"LAZERCRUNK with Traxman (Chicago)","slug":"lazercrunk","short":"anything goes bass music monthly","description":"Friday March 11th\r\n\r\nL A Z E R C R U N K\r\nthe anything goes bass music monthy\r\n\r\npresents special guest\r\n\r\nTRAXMAN\r\nlit city trax \/ planet-mu \/ teklife \/ chicago\r\n\r\nTraxman is a legend of Chicago ghetto house, juke and footwork. Soulful to the bone, designed for the future, with sounds raw, funky and fresh to light it up on the dancefloor. Get ready to work!\r\n\r\nand more sweating with\r\nCUTUPS & KEEB$\r\n\r\n Cover \/ 10PM - 2AM \/ 21+\r\n\r\nat the \r\nBRILLOBOX\r\n4104 Penn Ave\r\nPittsburgh\r\n\r\nLAZERCRUNK is every 2nd friday at Brillobox\r\nand features regular guests along with Cutups & Keeb$\r\nspinning fun, forward thinking dance music across the spectrum\r\nwith unique space design and lazer lighting","visibility_id":3,"event_status_id":null,"event_type_id":5,"is_benefit":0,"promoter_id":18,"venue_id":1,"attending":0,"like":0,"presale_price":"10.00","door_price":"10.00","soundcheck_at":null,"door_at":null,"start_at":"2016-03-12T03:00:00.000000Z","end_at":"2016-03-12T07:00:00.000000Z","min_age":21,"series_id":1,"primary_link":"http:\/\/lazercrunk.com","ticket_link":"","created_by":1,"updated_by":1,"created_at":"2016-02-25T13:20:39.000000Z","updated_at":"2016-02-26T07:19:18.000000Z","cancelled_at":null},
{"id":2,"name":"Trauma Harder Styles Tour 2016 - Pittsburgh","slug":"trauma pittsburgh","short":"hardcore tour with tons of big artists","description":"Produced by Trauma Live and BC1, the first major US hard dance tour hits The Rex Theater in Pittsburgh on Friday, February 26th.\r\n\r\nFeaturing: \r\nAlien T (IT)\r\nDJ BUZZ FUZZ (NL) \r\nDJ Deadly Buda (U.S.)\r\nDj Stephanie (IT)\r\nDr. Peacock (NL)\r\nMC Ruffian (NL) \r\nMeccano Twins (IT)\r\nRob Gee (U.S.)\r\nRotterdamterrorcorps (NL)\r\nSRB (NL)\r\nTommyknocker (IT)\r\n\r\nTickets on sale now: traumapittsburgh.eventbrite.com\/\r\n\r\nThis event is 18+ | Doors 7:30 p.m.","visibility_id":3,"event_status_id":null,"event_type_id":5,"is_benefit":0,"promoter_id":null,"venue_id":20,"attending":0,"like":0,"presale_price":"15.00","door_price":"20.00","soundcheck_at":null,"door_at":null,"start_at":"2016-02-27T01:00:00.000000Z","end_at":"2016-02-27T07:00:00.000000Z","min_age":18,"series_id":0,"primary_link":"","ticket_link":"","created_by":1,"updated_by":1,"created_at":"2016-02-25T23:43:41.000000Z","updated_at":"2020-12-09T08:59:41.000000Z","cancelled_at":null},
{"id":3,"name":"Totally Underground (90s throwback party)","slug":"totally underground","short":"Totally Underground (90s throwback party)","description":"This will be a tribute too the old school party scene.So bust out your big baggie ufos,spandex,bright neon colors and listen to some of the music that started it all.With some of your veteran DJS from the past,Newer DJs playing old school jams mixed with current jams!\r\n\r\n\r\nCUTUPS\r\nwww.soundcloud.com\/cutups\/\r\ndroppin 90s jams, mixed up rave and rap for your listening pleasure! \r\n\r\n\r\nSmartie\r\nEryn Evans\r\nPhunkphonic\r\nDJ Tanner\r\nSean Kramer\r\nJon Gordon \r\nPeterlee\r\nOmen\r\nWired Mic\r\nQueen beatz\r\n\r\n before midnight after\r\nhalf off tickets for anyone coming from the hardwell show, rjd2 or any other event!!!just show is a ticket,or wristband from the show!","visibility_id":3,"event_status_id":null,"event_type_id":8,"is_benefit":0,"promoter_id":null,"venue_id":21,"attending":0,"like":0,"presale_price":"15.00","door_price":"20.00","soundcheck_at":null,"door_at":null,"start_at":"2016-02-28T02:00:00.000000Z","end_at":"2016-02-28T09:00:00.000000Z","min_age":18,"series_id":0,"primary_link":"https:\/\/www.facebook.com\/events\/1736275429927149\/","ticket_link":"","created_by":1,"updated_by":1,"created_at":"2016-02-26T07:18:57.000000Z","updated_at":"2020-12-09T08:59:41.000000Z","cancelled_at":null},
...]
However, when change to using a route that collects events and paginates them and returns json, I get a different format, including some other fields including a header and date:
In my app.php for the route:
Route::resource('events', 'Api\EventsController');
In Api\EventsController:
$events = Event::all();
return response()->json($events);
Actual response:
HTTP/1.0 200 OK Cache-Control: no-cache, private Content-Type: application/json Date: Sun, 15 May 2022 18:57:15 GMT [{"id":1,"name":"LAZERCRUNK with Traxman (Chicago)","slug":"lazercrunk","short":"anything goes bass music monthly","description":"Friday March 11th\r\n\r\nL A Z E R C R U N K\r\nthe anything goes bass music monthy\r\n\r\npresents special guest\r\n\r\nTRAXMAN\r\nlit city trax \/ planet-mu \/ teklife \/ chicago\r\n\r\nTraxman is a legend of Chicago ghetto house, juke and footwork. Soulful to the bone, designed for the future, with sounds raw, funky and fresh to light it up on the dancefloor. Get ready to work!\r\n\r\nand more sweating with\r\nCUTUPS & KEEB$\r\n\r\n Cover \/ 10PM - 2AM \/ 21+\r\n\r\nat the \r\nBRILLOBOX\r\n4104 Penn Ave\r\nPittsburgh\r\n\r\nLAZERCRUNK is every 2nd friday at Brillobox\r\nand features regular guests along with Cutups & Keeb$\r\nspinning fun, forward thinking dance music across the spectrum\r\nwith unique space design and lazer lighting","visibility_id":3,"event_status_id":null,"event_type_id":5,"is_benefit":0,"promoter_id":18,"venue_id":1,"attending":0,"like":0,"presale_price":"10.00","door_price":"10.00","soundcheck_at":null,"door_at":null,"start_at":"2016-03-12T03:00:00.000000Z","end_at":"2016-03-12T07:00:00.000000Z","min_age":21,"series_id":1,"primary_link":"http:\/\/lazercrunk.com","ticket_link":"","created_by":1,"updated_by":1,"created_at":"2016-02-25T13:20:39.000000Z","updated_at":"2016-02-26T07:19:18.000000Z","cancelled_at":null},{"id":2,"name":"Trauma Harder Styles Tour 2016 - Pittsburgh","slug":"trauma pittsburgh","short":"hardcore tour with tons of big artists","description":"Produced by Trauma Live and BC1, the first major US hard dance tour hits The Rex Theater in Pittsburgh on Friday, February 26th.\r\n\r\nFeaturing: \r\nAlien T (IT)\r\nDJ BUZZ FUZZ (NL) \r\nDJ Deadly Buda (U.S.)\r\nDj Stephanie (IT)\r\nDr. Peacock (NL)\r\nMC Ruffian (NL) \r\nMeccano Twins (IT)\r\nRob Gee (U.S.)\r\nRotterdamterrorcorps (NL)\r\nSRB (NL)\r\nTommyknocker (IT)\r\n\r\nTickets on sale now: traumapittsburgh.eventbrite.com\/\r\n\r\nThis event is 18+ | Doors 7:30 p.m.","visibility_id":3,"event_status_id":null,"event_type_id":5,"is_benefit":0,"promoter_id":null,"venue_id":20,"attending":0,"like":0,"presale_price":"15.00","door_price":"20.00","soundcheck_at":null,"door_at":null,"start_at":"2016-02-27T01:00:00.000000Z","end_at":"2016-02-27T07:00:00.000000Z","min_age":18,"series_id":0,"primary_link":"","ticket_link":"","created_by":1,"updated_by":1,"created_at":"2016-02-25T23:43:41.000000Z","updated_at":"2020-12-09T08:59:41.000000Z","cancelled_at":null},{"id":3,"name":"Totally Underground (90s throwback party)","slug":"totally underground","short":"Totally Underground (90s throwback party)","description":"This will be a tribute too the old school party scene.So bust out your big baggie ufos,spandex,bright neon colors and listen to some of the music that started it all.With some of your veteran DJS from the past,Newer DJs playing old school jams mixed with current jams!\r\n\r\n\r\nCUTUPS\r\nwww.soundcloud.com\/cutups\/\r\ndroppin 90s jams, mixed up rave and rap for your listening pleasure! \r\n\r\n\r\nSmartie\r\nEryn Evans\r\nPhunkphonic\r\nDJ Tanner\r\nSean Kramer\r\nJon Gordon \r\nPeterlee\r\nOmen\r\nWired Mic\r\nQueen beatz\r\n\r\n before midnight after\r\nhalf off tickets for anyone coming from the hardwell show, rjd2 or any other event!!!just show is a ticket,or wristband from the show!","visibility_id":3,"event_status_id":null,"event_type_id":8,"is_benefit":0,"promoter_id":null,"venue_id":21,"attending":0,"like":0,"presale_price":"15.00","door_price":"20.00","soundcheck_at":null,"door_at":null,"start_at":"2016-02-28T02:00:00.000000Z","end_at":"2016-02-28T09:00:00.000000Z","min_age":18,"series_id":0,"primary_link":"https:\/\/www.facebook.com\/events\/1736275429927149\/","ticket_link":"","created_by":1,"updated_by":1,"created_at":"2016-02-26T07:18:57.000000Z","updated_at":"2020-12-09T08:59:41.000000Z","cancelled_at":null},
...]
Can anyone point me to what the exact default response is in the first case? I'd like to make sure I use that in my controller.
Please or to participate in this conversation.