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.
Use curl as shown below to download the go-pear.phar file or just download the go-pear.phar file via your browser. $ curl -O https://pear.php.net/go-pear.phar $ php -d detect_unicode=0 go-pear.phar You’re now ready to configure PEAR for installation. First you need to change the Installation Base. So type 1, and then press Enter. Enter /usr/local/pear Press Enter. … Read more
Didn’t know Carbon parse has a ‘W‘ format week! Also, if the column is a date or datetime field you can skip Carbon::parse().
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
I search for this more than I thought I would. As the title suggests, the following allows you to group items of an array by its key. By Tim Cooper
Redis has a maxmemory-policy where it decides how to handle keys when memory limit is reached. noeviction will return errors when the memory limit is reached. allkeys-lru will remove less recently used keys first. volatile-lru will remove less recently used keys first that have an expiry set. allkeys-random will evict random keys. volatile-random will evict … Read more
If a user make two request in succession and you want to cancel the first, here’s how to do it in Axios. Works like a charm. Provided by NicksonYap, some iteration of iterations. https://github.com/axios/axios/issues/1361#issuecomment-417880626
I was having trouble understanding the work-flow and boilerplate of using Vuex state in my components. This article by Markus Oberlehner helped me understand how to bind elements to the state and how to use vuex-map-fields to simplify the process. Here’s the manual way. Read his post to find out about vuex-map-fields https://markus.oberlehner.net/blog/form-fields-two-way-data-binding-and-vuex/