Posts tagged #php
PHP trait declaring a contract
Throttle Simultaneous API Requests with Laravel
by Liam Hammett · 2 minute read · #open-source #php #laravel
Laravel comes with a handy ThrottleRequests
middleware out-of-the-box that blocks users of an API from being able to send more than a particular amount of requests within a defined amount of time.
This is extremely useful for preventing an API from being abused by spammed requests, but isn’t suitable for every use case.
What about an API call that takes a lot of limited processing power, or performs an action that simply can’t be running twice at the same time?
Laravel Set .env File Variable
by Liam Hammett · 2 minute read · #open-source #php #laravel
Need a quick way to set an environment variable from the command line that’ll save it to the Laravel .env
file?
Here’s a command to do just that.
PHP Shareable Social Media Links
by Liam Hammett · 2 minute read · #open-source #php
I recently had the need to generate various “shareable” links to help share a particular URL to different social media platforms. The problem is that every platform requires information in a slightly different way.
Lo and behold, just a few days later, Dennis Smink shared their method of doing so in their article “Laravel Shareable Trait” that covers the few biggest platforms.
PHP Function Chaining with Pipes
by Liam Hammett · 11 minute read · #php
Back in December 2016, freelance developer Sebastiaan Luca wrote a post on their blog inspired by an RFC proposal for PHP core about chaining functions, and here I am going to be responding to that blog post.
I highly recommend reading the aforementioned post and RFC to get an understanding of what function piping is as they do an amazing job at explaining the benefits it brings.
In short; it’s syntactic sugar to help make code more readable.