If you want to know how many times your Laravel query is hitting the database you can use this snippet by @Tarasovych from StackOverflow. Pretty handy!
Laravel’s with() is an easy to use query builder tool to fetch relationship. Once you’ve established the relationship in your model file you can do this. But this query has the downside of hitting the database twice, or however many relationships you query. And if you’re running it on a big scale application, it can … Read more
What are some scraper options for Laravel? Well, Dusk works well if you’re just working in dev and testing but the following list can work for various cases. I’ve listed the four from what seems to be most reliable to least reliable depending on your use case. For instance, it seems like only panther and … Read more
Various ways to set value if the value does not exist in PHP. The whole discussion summarized nicely at the end by @ben221199:
I’ve probably tested 30 different snippets of code. Yeah, yeah, I should probably understand what I’m actually doing first. But here’s the one that most reliably worked. Obviously, from css-tricks who writes it in jQuery. Below is the vanilla version with reliable flair.
The Problem Do you see a json ajax response instead of the page you were expecting when hitting the back button? This can happen if you use the the same routes for your html and ajax like so. The problem is that the browser (depending on the browser) decides to cache data that is passed … Read more
I’m experiencing Heroku’s H18 errors uploading large files and passing it to an S3 instance. It happens itermittently. The Heroku docs say the following. Usually, an H18 indicates that a response has multiple stages – forinstance, streaming chunks of a large response – and that one of thosestages has thrown an error.https://devcenter.heroku.com/articles/error-codes#h18-server-request-interrupted The docs further … Read more
Detect mobile usage in Vue with screen width: With browser useragent: With npm package (https://www.npmjs.com/package/vue-mobile-detection):
When adding a column in a Laravel migration, you can add the column in a specific order by using the following format in your schema builder. Note that this only works with MySQL 🙁
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