Blog Detail

31

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

arrow_back Use Laravel Settings to Create Your Website & Model Settings

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.

Published at : 31-03-2022

Author : Rizwan Aslam
AUTHOR
Rizwan Aslam

I am a highly results-driven professional with 12+ years of collective experience in the grounds of web application development especially in laravel, native android application development in java, and desktop application development in the dot net framework. Now managing a team of expert developers at Codebrisk.

Launch your project

Launch project