In this tutorial we're going to investigate creating view objects in Laravel. On the home page you will display a list of the latest posts but on a category page you'll display a list of posts for the specific category.
Using the new Responsable interface from Laravel 5.5 we can move this view functionality into it's own class to reuse the view and parameters from different controllers.
class HttpResponse implements Responsable This will then require a toResponse() method which will be called when you return this object from a controller.
This object will be responsible for collecting the posts and returning them with the blade view.