Use Laravel Settings to Create Your Website & Model Settings

Use Laravel Settings to Create Your Website & Model Settings cover image

The Laravel Settings Package has been developed to allow you to add general settings to your website in a simple and easy way, you can add settings for a specific model item as well, Let’s start using it in simple steps. The Laravel Settings package requires Laravel 8+.

Installation

To install and setup the Laravel Settings we will follow a few steps:

Install via composer

composer require yazan/laravel-settings

Publish migrations

php artisan vendor:publish --tag=settings

Run migrations

php artisan migrate

Quick Example

General Setting

we will call the set method from the Setting class and set the key and value simply

$setting =  \Setting::set('age', 18);

Here we retrieve data from Setting

$setting =  \Setting::get('age');
// 18

Model Setting

we can set setting for specific item of Model as below

$user = User::find(1);
$user->setSetting('age', 18);

Here we retrieve the Setting from model

$user->getSetting('age');
// 18

also, we can retrieve Setting as a group

$user->getSettingGroup('default');
//['age' => 18]

Here’s the basic introduction of this package, If you want to learn more you can visit its complete documentation on Github.

Written by

Rizwan Aslam

Founder and CEO of CodeBrisk, with years of experience building web applications with Laravel and leading a team of expert developers.

More about Rizwan
Book a free call
Book a call with CodeBrisk