Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Laravel News:
Building a Laravel Translation Package – The Database Driver
Dec 18, 2018 @ 16:54:52

On the Laravel News site they've posted the latest tutorial in their series covering the creation of a translation package. In this latest article they cover the creation of the database driver to replace the previous file-driven content handling.

In the previous article of the series, we talked about how to handle missing translations, which brings us very close to making the package feature complete. To finish up the build phase of this series, we will discuss how we go about adding a database driver.

Thanks to defining the interface for the data handling previously, redefining the handler for the database is simpler. He includes the code for:

  • the migrations to create the languages and translations tables
  • the models for both tables and their relations to each other
  • creation of the database driver using the interface

His code includes methods for getting either single or multiple translations including fetching them by language. He then updates the "resolve" method to allow defining the driver to use in the configuration rather than being hard-coded.

tagged: database driver translation package tutorial series

Link: https://laravel-news.com/building-database-driver


Trending Topics: