Skip to main content
Back to packages
1,496 GitHub stars

spatie/laravel-settings

View on GitHub

Description

Store strongly typed application settings

his package allows you to store settings in a repository (database, Redis, ...) and use them through an application without hassle. You can create a settings class as such:

class GeneralSettings extends Settings
{
public string $site_name;
 
public bool $site_active;
 
public static function group(): string
{
return 'general';
}
}

If you want to use these settings somewhere in your application, you can inject them, since we register them in the Laravel Container. For example, in a controller:

class GeneralSettingsController
{
public function show(GeneralSettings $settings){
return view('settings.show', [
'site_name' => $settings->site_name,
'site_active' => $settings->site_active
]);
}
}

You can update the settings as such:

class GeneralSettingsController
{
public function update(
GeneralSettingsRequest $request,
GeneralSettings $settings
){
$settings->site_name = $request->input('site_name');
$settings->site_active = $request->input('site_active');
 
$settings->save();
 
return redirect()->back();
}
}

Related Content on Laravel Daily

Video

Recent Courses on Laravel Daily

Laravel 13 Starter Kit Teams and Customizations

10 lessons
33 min

Roles and Permissions in Laravel 13

14 lessons
57 min

How to Structure Laravel 13 Projects

16 lessons
1 h 32 min read

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.