Laravel get request parameters: request() vs $request->input()

There are many ways to get the request parameters in Laravel, such as request(), $request->input(), $request->get(), but there are a little different between request() and $request->input() when the parameter is not actually passed. Sometimes it maybe cause some unexpected behavior, Let’s see: 1 2 3 4 5 6 7 Route::get('/test', function (Request $request) { dd( request('key', 'default'), $request->input('key', 'default'), $request->get('key', 'default'), ); }); When our request like this: http://localhost/test?key=, yes, we do not actually set a value for the key, the output will be:

远程开发(瘦客户端开发)指北

为什么需要远程开发 首先需要明确,本篇文章说的远程开发,不是指“远程开发工作”,而是指“远程开发环境”,在网上通常也叫瘦客户端(机)开发。 是指

How to iterate big dataset in Laravel without memory exhausted

Imagine that you have to iterate a big table in Laravel, the words “big table” means that the table not only thousands of rows, but also millions of rows. Intuitively, we may use the all() or get() method of the model to retrieve all the rows, and then iterate them. But our memory is limited, use those function may cause a memory exhausted error. Here, I will give you three ways to do this.

Laravel Tips: Is the code running in http request?

We know, the code in Laravel can run in different environment, such as http request, queue, artisan command and even in Tinker. Sometimes, we need to know the if the code is running in a http request or not. Fortunately, Laravel provide a function to do this: app()->runningInConsole(). If the code is running in a http request, it will return false, otherwise, such as in queue, artisan command, or in Tinker it will return true.

Use Docker Compose Healthy Check To Run Command Periodically in a Container

In my work, I have a domain that use the certbot container to renew the ssl certificate from letsencrypt. It has two containers work together, the certbot container and the nginx container. If the certbot container renew the certificate successfully, it will replace the old certificate file with new one. So, the nginx needs to reload the certificate file. Unfortunately, the certbot container doesn’t have a way to notify the nginx container to reload the certificate file.