Hey @aschmelyun , nice to see you around.
The image uploading series is top notch and helped as I was just in need to implement multiple async uploads.
Some remarks:
1.
$request->root() will return the current't request URL, which will always match the URL in APP_URL.
OP wanted to check if the client consuming the endpoint is an external one, that is why I suggested him to check the Referer header, which is not always reliable, but is the best bet one could make with default setup. The downside is that any external clients that are not a browser might not include the Referer header.
One other option would be to check for a header he is always sure he would manually add on the scripts from his own applications to be absent. But that could also be faked once an external agent knows about it.
2.
As @michaloravec pointed out, the env(...) helper should only be used inside configuration files.
As per Laravel docs:
If you execute the config:cache command during your deployment process, you should be sure that you are only calling the env function from within your configuration files. Once the configuration has been cached, the .env file will not be loaded and all calls to the env function for .env variables will return null.
Reference: https://laravel.com/docs/8.x/deployment#optimizing-configuration-loading
And as, in the same link above, it is recommend to cache configuration in production, due to performance issues, it is not advised to use the env() helper outside of config files.
Further reading:
Hope this helps =)