Skip to content

Instantly share code, notes, and snippets.

@uno-de-piera
Created June 12, 2019 06:21
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 uno-de-piera/f99db451d33da6e7cd2ea8f3319dab18 to your computer and use it in GitHub Desktop.
Save uno-de-piera/f99db451d33da6e7cd2ea8f3319dab18 to your computer and use it in GitHub Desktop.
<?php
namespace App\Http\Controllers;
use App\Models\Post;
class PostController extends Controller
{
public function index () {
$posts = Post::select('id', 'user_id', 'title', 'content', 'created_at')->with([
'user' => function ($query) {
$query->select('id', 'name');
}
])->paginate(config('constants.pagination.per_page');
return view('posts', compact('posts'));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment