#10 Throwing validation exceptions, stack and push in Blade, and more
Welcome to the 10th Andy's Web Dev Tips newsletter! Here's a few things from the last couple weeks:
Manually throwing Laravel validation exceptions
@JuanDMeGon posted the following code snapshot on Twitter:
If you’re using Laravel’s request validation in your methods, this is a perfect override to replace the default messages passed back to the frontend of your app. Just replace the ‘field’ attribute with the name of your input field and customize the text returned back to the user when the validation fails.
For instance, if I have a field called birthday to check if a user is over 21 (by subtracting that date from the current date), I’d like to replace the generic validation failed message with something like “Sorry, you’re not old enough”.
CSS background-repeat properties you might not know about
@addyosmani posted something super helpful on Twitter that I had absolutely no idea about. For the longest time whenever I’ve needed to repeat a background on an element, I used the background-repeat: repeat property. It usually works well for what I need it to, but it can clip off the edges of your background that doesn’t perfectly tile across the element. There’s two other values you can use that’ll fix that!
Here’s a breakdown of what they do:
background-repeat: round - When increasing or decreasing your element size, it scales the individual tiled images to make room for more or less
background-repeat: space - When increasing or decreasing your element size, it leaves space between the individually tiled images to make room for more or less
Click this link to check out the original Twitter post and see a short gif demonstrating those explanations above.
Using @stack and @push Blade directives
I recently learned about a super helpful Laravel Blade directive that I’ve since used in one of my projects. Check out this code example:
By adding a @stack with your desired name, you open up an area that you can @push items to. Push can be used multiple times throughout your template file(s), and will render out a list of all of the items that you pushed to that designated @stack!
Adding Markdown link attributes
@keithdamiani tweeted out helping with a Markdown question and kind of blew a few people’s minds with a simple hint. You can create a typical standard link in Markdown by using [link description](http://example.com), but what if you wanted to have that link open in a new tab, you’d need to add an attribute. Well, if the parser used supports Markdown Extended, you can use:
That’s it for now! If you have any questions about the above, or have something you’d like me to check out, please feel free to let me know on Twitter.