Skip to content

Instantly share code, notes, and snippets.

@tnylea
Created April 20, 2017 17:36
Show Gist options
  • Save tnylea/5d0ff11438654a902767ec8f617cb50e to your computer and use it in GitHub Desktop.
Save tnylea/5d0ff11438654a902767ec8f617cb50e to your computer and use it in GitHub Desktop.
Post Controller return
<?php
public function show($slug, $page = null)
{
// GET ALL YOUR POST DATA
// $post = Post::where('slug', '=', $slug)->firstOrFail();
// $data = ...
// Add this peice to the end of your show method for your post
if($request->ajax()){
return response()->json(['url' => url('/'), 'post' => $post, 'view' => view('partials.post', $data)->render()]);
} else {
// return the original post view if it is not ajax
return view('post', $data);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment