Zebra Codes

How to Perform an Unbuffered Query in Laravel

26th September, 2023

If you wish to process a very large number of rows from a database then it may be prohibitively expensive to load them all into memory first. Laravel’s chunk() function may look like the solution however this performs a query for each chunk and is therefore extremely slow.

The ideal solution is to disable query buffering and thereby only ever have a single row in memory at once. Note that this option is specific to the MySQL PDO driver.

Read More >

Impersonation in Laravel 10 with Sanctum

16th August, 2023

Impersonation is a useful tool: it allows an administrator to view the website as if they were logged in as another user, but without having to know their password. The Laravel documentation implies that you can do this using Auth::loginUsingId(), but you will find that this doesn’t work.

Read More >

How to use Laravel + Vite from Docker

16th January, 2023

If you are running Laravel inside a Docker container and using Vite for Javascript/CSS bundling, you may find that the files fail to load when you view your website. You instead see one of the following errors:

  • GET http://127.0.0.1:5173/@vite/client net::ERR_CONNECTION_REFUSED
  • GET http://0.0.0.0:5173/@vite/client net::ERR_ADDRESS_INVALID
Read More >