{ All snippets }

Tweetsnippet is a curated list of tips and tricks from Twitter.

Gurmandeep Singh

Gurmandeep Singh @iamgurmandeep

#Laravel Validation Tip ๐Ÿ”ฅ You can use a closure instead of a rule object if you only need a custom rule once throughout your application. The closure receives the attribute's name, the attribute's value, and a `fail` callback that should be called if validation fails. https://t.co/Bl0EkmArzu

Matt Kingshott ๐Ÿ

Matt Kingshott ๐Ÿ @mattkingshott

๐Ÿ”ฅ #Laravel Tip: A common pattern in websites that offer searchable content, is to suggest content when the user's query returns no results. Laravel can help with this via the 'existsOr' method. Here's an example that finds an alternative vacation destination. https://t.co/dvYvcJIuNr

Maxime Duprรฉ ๐Ÿฅน๐Ÿš€

Maxime Duprรฉ ๐Ÿฅน๐Ÿš€ @maximehugodupre

I just discovered that you could add opacity to HEX colours (as opposed to RGBA) ๐Ÿคฏ๐Ÿคฏ You have your initial colour, e.g. #FFAABB You want to add opacity? Add two more hex chars. e.g. #FFAABB99 The last two chars will control opacity from 00 (0) to FF (1). ๐Ÿคฏ๐Ÿคฏ๐Ÿคฏ

CSS
Matt Kingshott ๐Ÿ

Matt Kingshott ๐Ÿ @mattkingshott

๐Ÿ”ฅ #Laravel Tip: When accessing APIs, consider using a unique user agent. That way, if there's a problem, the owner of the API can see who you are and get in touch. It doesnโ€™t guarantee they will, but you might be lucky and avoid being blocked. https://t.co/cJsLiQSojH

PHP
Matt Kingshott ๐Ÿ

Matt Kingshott ๐Ÿ @mattkingshott

๐Ÿ”ฅ #Laravel Tip: Instructing the database to delete a huge number of records is likely to make it fall over (esp. when using cascade deletion). However, you can avoid this by staggering the process into batches and adding pauses to allow the database time to catch up. https://t.co/xkv0If70ac

Matt Kingshott ๐Ÿ

Matt Kingshott ๐Ÿ @mattkingshott

๐Ÿ”ฅ #Laravel Tip: A common task when performing an authorisation check, is to verify if a particular model (such as the authenticated user) owns another model (e.g. a blog post). Since you're likely to do this a lot, consider adding an 'Ownership' trait to your models: https://t.co/U5ZPfAm9PS

Daniel Eckermann

Daniel Eckermann @ecrmnn

Another piece of Laravel smoothness ๐Ÿ„ Did you know that you can use *whereBelongsTo* instead of a regular *where*? ๐Ÿƒ https://t.co/FdjPA3nbqV

Matt Kingshott ๐Ÿ

Matt Kingshott ๐Ÿ @mattkingshott

๐Ÿ”ฅ #Laravel Tip: When storing database notifications, you may want to avoid adding duplicates, so that a user's โ€œfeedโ€ only contains unique content. You can do this by adding a hash of the content and then enforcing a unique constraint on the table. https://t.co/ahbbMYxsA8