Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Laravel return json from url
// Create an action for the route
public function postToJson()
// Query here for json you want to return
$post = Post::all();
// Send to json response
return Response::json($post->toArray(), 200);
// Create route for json file
Route::get('/posts.json', 'PostsController@postToJson');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment