Laravel – Carbon and Queries


Carbon is probably the most effective way to handle DateTime strings flawlessly and implement PHP code that everybody can easily extend or debug.

In the following example, I would like to demonstrate how you can filter a collection in Laravel by using Carbon. As you can see, the below example will simply return all People who have registered in the past two weeks.

The method subWeeks() will do all the work for you and return a valid DateTime string from 14 days ago which can be used for the whereBetween query method. If you prefer using days, you can simply use subDays() instead.

One possible use case could be a front-end controller that handles AJAX requests.

PHP message: PHP Fatal error: Interface ‘SessionHandlerInterface’ not found in /var/www/src/vendor/ laravel/framework/src/Illuminate/Session/FileSessionHandler.php on line 10

Today I successfully installed my first October CMS project locally via composer / command line. The installation was pretty straightforward and worked surprisingly well on my Alpine Linux docker container which includes NGINXPHP-FPM and MariaDB.

However, when I tried to open the front-end I got the following error.

After a quick research I found the solution on Stackoverflow. I basically forgot to install the PHP extension php7-session inside my docker container. I manually installed the missing extension, but also updated my Dockerfile in case I have to rebuild my container.

After that I manually killed all PHP processes to make sure php-fpm loads the new extension with the next page reload.