Skip to content

Instantly share code, notes, and snippets.

@icemancast
Last active August 5, 2016 13:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save icemancast/11293902 to your computer and use it in GitHub Desktop.
Save icemancast/11293902 to your computer and use it in GitHub Desktop.
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