Dealing with Global Options in Your Laravel Project

How to easily handle global options for multiple purposes

Houston, we got a ... situation

Sometimes you need to store some key value pairs in your project, but where? In my situation I had multiple options to store. Some of the options should change later in the process so it should be possible to update them as well. For example: check the status from a third party service and store the status or some company data.

What could we do?

We can create a dedicated options table where we can store the key value pairs. If we make it easy to request, add, update or delete them, then we have the flexibility to handle these options everywhere in our project.

Automated with a package

That’s why we created the package laravel-options. It automates this process for you and adds a nice option helper function to set (or get) your options.

For the CLI’ers among us it’s also possible to set up your options via CLI by doing:

php artisan option:set {key} {value}

In your application you can easily set an option by doing:

option(['key' => 'value']);

or get an option:

option('key');

More details on installation and usage, check the GitHub repo.


Hopefully this will help you and your project to easily handle global options. Give it a shot and let us know what you think!

I’m also curious for which purposes you’re going to use it. Let me know in the comments below.