Localization in Laravel

In this post, I will go to explain how to localize a Laravel application. The application will support English, Spanish and Galician languages. This is a real example to translate the https://wptranslator.jesusamieiro.com web app. You can find the source code on GitHub.

The steps to localize the application will be:

  1. Create a configuration file to store the languages that will be used by the application.
  2. Define the default language for the application.
  3. Add the translation functions in the views.
  4. Create the JSON translation files.
  5. Create the middleware that updates the application language.
  6. Add the selector in the main view to enable the end-user to change the application language.
  7. Add the route for the change event of the previous selector.
  8. Add the controller to receive the change event from the previous selector.

Laravel, WordPress e a API REST: usando WordPress como xestor de contidos en aplicacións Laravel. WordCamp Lisboa 2019

Neste enlace (PDF, 1,04 MB, galego) deixo as transparencias da presentación «Laravel, WordPress e a API REST: usando WordPress como xestor de contidos en aplicacións Laravel» da WordCamp Lisboa do día 18 de maio de 2019.

A proba de concepto podedes encontrala en GitHub, no seguinte enlace: Laravel, WordPress and the REST API.

Execute and test only one method with Laravel Dusk

When you are running Laravel Dusk tests from the terminal, with the command

$ php artisan dusk

sometimes you need to execute and test only one method. You can do it with the “–filter” parameter and the name of the method:

$ php artisan dusk --filter testUserInsertBlankSpacesAndThePasswordDoesNotChange

“403 Invalid signature” when I try to verify an email in Laravel

When I try to verify an email in Laravel I get the error:

403 Invalid signature

The problem is a misconfiguration in the nginx configuration file (the Server Blocks).

The bad configuration was

location / {
    try_files $uri $uri/ /index.php?q=$uri&$args;
}

The good configuration is

 location / {
    try_files $uri $uri/ /index.php?$query_string;
}

UUID en Laravel

Un UUID (identificador único universal o universally unique identifier) es un número de 16 bytes (32 dígitos hexadecimales), referenciado habitualmente mediante cinco grupos separados por guiones 8-4-4-4-12, lo que genera un total de 36 caracteres (32 dígitos y 4 guiones), que se encuentra estandarizado en el RFC 4122.

Se puede usar en múltiples ámbitos:  claves primarias en tablas de bases de datos relacionales, identificación única de objetos, componentes,…

Para poder usarlo en un proyecto generado con Laravel dispongo de la librería ramsey/uuid, que se instala como dependencia de Laravel, y que permite generar UUID de tipo 1, 3, 4, y 5, de acuerdo con el RFC 4122. En esta artículo voy a explicar las características de cada tipo de UUID y cómo se generan el Laravel usando la librería mencionada.