Laravel Pro Tips
#collections
If you ever need to build a quick CSV export command for your Laravel application. This is how I would recommend doing it. Open a resource to StdOut and then chunk your results and write them to the output using fputcsv(). It'll handle the CSV output perfectly π #laravel
Peter Fox
#eloquent #collections #null
π‘ #Laravel Tips of the day π ππΌπ»βπ ππΆπΉππ²πΏ π―π π‘π¨ππ πΆπ» ππΌπΉπΉπ²π°ππΆπΌπ»π: We can filter by NULL in Eloquent, but if we're filtering the collection further - filter by empty string, there's no "null" in that field anymore. #php #backend
vigowebs
#joins #collections
You've probably joined an array into a comma separated string before. But what about when you want the last one to say "and"? With Laravel collections it's a breeze π
Daniel Eckermann
#Laravel Tip: If you have a collection, and you want to get items from the end of it, you may pass a negative integer to `take()` method to take the specified number of items from the end: Here is an example:
Oussama Sid
#eloquent #models #collections
π₯ Laravel Tip: If you have an eloquent collection, and you want to update every model. You can use the `toQuery` method, and execute the update with only one query instead of looping through the collection.
Cosme Escobedo
The every method may be used to verify that all elements of a collection pass a given truth test. #Laravel
Teacoders
#collections #filter
Laravel Collections tip. To remove all falsy values from the collection, simply call filter without any arguments β¨
ππ» Laravel tip of the day You can use the "higher order messages" to refactor the logic that returns custom fields to a separate model method and feed it to the other collection method. For instance, the `map` method. This makes things tidier while building queries! #Laravel
Amit Merchant
Just discovered that there is a method to check whether a Laravel collection contains exactly one item or not. I've written my last count() === 1 π
No articles were found.