How to Display a short List of Posts on a "Home Dashboard Page"
This may be Laravel 101, but I am a total newbie and have not seen an example of this yet. I have a full blog post view working with pagination that displays all posts. This is NOT the home page of the project. On the home page of the project, I want to display the latest 20 posts with their titles, featured image and excerpt. In addition, I want there to be many other multiple data objects used on the same page... as in a Dashboard. In terms of best practices, what is the correct way to do this in Laravel?
I totally get the the idea of having a view, controller, model, factory etc dedicated to posts. But how do you mix things up on a page that includes smaller bit size data objects from other parts of the project, as in a dashboard?
with just Laravel you would do it by doing the same eloquent query on your dashboard index controller as on your post controller, just make sure you add use App\Model\Posts; so the model is available to the controller
then pass it to your view via compact, then you can run your for each loop for the posts, if you are trying to make it available on every page that is using a dashboard component then you could use a view composer and pass it that way as well
Thank you both for your response. I can see how both responses are similar. Talinon's detailed example code just made it a little easier on me being a newbie.
Hi all, I am able to get posts (list) into the preview blade (home dash) yet I cant find some knowledge base to help me reduce the initial word count displayed, its all overlapping each other .. your direction would be greatly appreciated.
Here is my code: