Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

syntaxerron's avatar

How to use Spatie Settings Package?

I am building an SPA that requires a global settings and I happen to come across a package that handles this kind of data. I wanted to try the settings package from Spatie and I want to know if anyone here had experience using the package? I was kind of confused how I am going to fetch the all the settings data aside from DB::table('settings')->get(). I know it's kind of a dumb question, I've read the instructions from their Github repo but somehow confused. I can't even find an article about it. If someone knows how to implement it, thank you in advance for the help.

api.php:

Route::get('settings', 'API\v1\SettingController@index')->name('settings');

SettingController.php

public function index()
    {
        return response(DB::table('settings')->get(), 200);
    }

GeneralSettings.php

<?php

namespace App\Classes;

use Spatie\LaravelSettings\Settings;

class GeneralSettings extends Settings
{
    public string $site_name;
    public bool $site_active;

    public static function group(): string
    {
        return 'general';
    }

    public static function repository(): ?string
    {
        return 'settings';
    }
}


0 likes
3 replies
Artwork's avatar

@Snapey , thank you! The package is interesting, but is a different one nowadays, yet is indeed similar. Laravel Settings one offers some additional features, including validation, cache, casts, and multiple repositories like the database or, if you'd prefer, a JSON some would implement using a definite interface for it.

@syntaxerron , I've tried to implement something similar to the package without knowing about its existence, and got an appreciated response. Today, though the docs are currently missing a few details, it's already better, and please consider checking it out once more if you haven't yet: README.md.

For instance, in order to retrieve the typed value from the database or cache you could use its own service container implementation:

$generalSettings = app(GeneralSettings::class);

dump([
    'allSettings' => $generalSettings,
    'siteName'  => $generalSettings->site_name;
]);

Currently, there's no helper like settings(/* ... */), but it's possible, of course, if required.

Please or to participate in this conversation.