In this episode, we're making our codebase cleaner and easier to work with by adding some handy helper functions!
First, we create a view
helper. Instead of having to write out the full logic for rendering a view and returning a response inside our controllers, the new helper lets us do this in one simple line. You can use it to render your views and return the result right away, making your controller actions much simpler and tidier.
Next, we add a config
helper. This function lets you quickly fetch configuration values from anywhere in your app without having to manually access the config service out of the container each time. Just pass the config key (and an optional default), and you've got what you need.
We take a quick look at how this makes things like our ViewServiceProvider
much neater, swapping out some longer code for a one-liner using our new helper. Finally, there's a little debugging at the end—it's just a reminder to declare your helpers as simple functions, not as methods on a class.
By the end of the episode, you’ll have these helpers ready to go, and you’re encouraged to add any others you find useful. This will keep your codebase clean and your day-to-day programming much nicer!