This episode is for members only

Sign up to access "Build A Static File Blog with Laravel" right now.

Get started
Already a member? Sign in to continue
08. Refactoring to use Blade components


Before we go ahead and add tags to our blog post, let's create another blade component
for the author information, because we're actually using this in two different places. Normally, I wouldn't refactor this early, but if we're working with something like this, where we want the styling to be very consistent, it's worth moving over to a new component. So I'm going to create out a blade component in here called, let's think, let's say PostMeta.
And again, we'll use that view flag in here because we don't really need a class associated with this component. It's going to be very, very simple. Okay, so we can head over to our index, we can grab what we need here, and we can add that to our PostMeta.blade.php component. We're going to be adding our tags in here later and iterating through them. So it kind of makes
sense for the PostMeta to be in its own component, because we don't want to be iterating over on lots of different pages. So we can just switch this up now. So let's go ahead and say X PostMeta, and then we can just pass the post through here that we want. So let's pass this in as post, and this is on our index, so we should see no difference at all. We can now reuse this component
over here, and then when we add to this later, we're just going to have these appear in both places. So let's go down to our show page, and we'll do the same here, and there we go. Great, so we have a little bit more consistency now. It's looking nice, and when we add our tags in the next few episodes, we can just add them to this component, and they will always be there.
13 episodes1 hr 11 mins


Let's build a ridiculously fast blog from scratch in Laravel, entirely driven by markdown files. No database required!

Your blog will feature everything you're used to, like syntax highlighting, post tagging and pagination. Plus, it'll render in record time.

Once you're done with the course, you'll be able to add on additional features with ease, style it up how you want and quickly create new posts since there's no need for an admin panel.

Alex Garrett-Smith
Alex Garrett-Smith
Hey, I'm the founder of Codecourse!


No comments, yet. Be the first to leave a comment.