This is a shoutout to Laravel’s Query Builder method distinct(). I feel sad and embarrassed that I didn’t know about it sooner. There are a lot of instances where I need to get a column’s unique values. And instead of using groupBy() and wasting a lot of resources. You can use distinct(), which will search … Read more
To validate an array of objects in Laravel, you can use the * identifier for each item in an array, and use the “.” syntax to point to the property. So the above would read, “Each item in the row array’s title is required,” etc.
Didn’t know Carbon parse has a ‘W’ format!
Need to convert a float or string into a currency format in Laravel? Here are two quick methods. Use PHP’s number_format() in your blade template. You can also add the following to your AppServiceProvider’s boot method. Good luck!
How do you cache efficiently in Laravel? Trying to figure out an efficient way to serve data using the least amount of resources is always a challenge to face when scaling. How much of the data to process in the front vs back end. When to cache and how to handle the scope of what … Read more
If you are using Laravel’s firstOrCreate() method and get a unique id violation error, there is a chance you have repopulated your database retroactively in Postgres. Postgres triggers the next id in the sequence on row creation instead of on import. So it thinks the next sequence in the id field is an existing ID … Read more
The Story (skip if ya just want the code) I’ve fussed with this problem for weeks. If you need to import massive amounts of csv data (100k to 10mil) to your Laravel site there’s a lot of broken information. Some of it is outdated, others are just bits and pieces. But here’s generally how the … Read more
Laravel’s official documentation about many to many sync states the following on syncing a third table value. How do you actually get those values however?
I’ve been having to look up relationship schemas too frequently and haven’t found a decent place that outlines them with migration and eloquent relationship declaration side by side. So if you’re looking for how to build a migration for (insert here) relationship, here it is. *Based on Laravel 7 One to One One to Many … Read more
Unsuccessful with the making columns case-insensitive framework level, I had to go deeper. Here’s how I changed my Postgres columns to be case-insensitive, and ultimately solve my model relationship problems. CITEXT Extension for Postgres You needs to provision the extension to the database. If you use Heroku (like me here’s a simple step). The citext module provides … Read more