Pharaonic
Loading...

Getting Started

Settings

# Why Settings?

Settings helps to store and retrieve general settings or model settings in Laravel.

# Installation

Install the latest version using Composer.

1composer require pharaonic/laravel-settings
2php artisan migrate

# General

Using settings helper to store and retrieve the general settings.

#General Set

This is how you can store the general settings, there are 3 ways so you can use the one that you like.

1// Way 1
2settings()->status = false;
3 
4// Way 2
5settings()->set('off_message', 'Maintenance');
6 
7// Way 3
8settings()->set([
9 'status' => true,
10 'off_message' => 'Maintenance'
11]);
12 
13// Save all settings
14settings()->save();

#General Get

This is how you can retrieve the general settings, there are 3 ways so you can use the one that you like.

1// Way 1
2// Returns string|null
3settings()->status;
4 
5// Way 2
6// Returns string|null
7settings()->get('off_message');
8 
9// Way 3
10// Returns Collection
11$data = settings()->get(['status', 'off_message']);
12echo $data->off_message->value;

# Model

Using Settingable trait to store and retrieve the settings of a specific model.

# Inclusion in Model

You have to include Settingable first in your model.

1namespace App\Models;
2 
3use Illuminate\Foundation\Auth\User as Authenticatable;
4use Pharaonic\Laravel\Settings\Traits\Settingable;
5 
6class User extends Authenticatable
7{
8 use Settingable;
9}

# Model Set

This is how you can store the settings of a specific model, there are 3 ways so you can use the one that you like.

1// Way 1
2$user->settings->multilingual = true;
3 
4// Way 2
5$user->settings->set('notifiable', true);
6 
7// Way 3
8$user->settings->set([
9 'multilingual' => true,
10 'notifiable' => true,
11]);
12 
13// Save all settings
14$user->settings->save();

# Model Get

This is how you can retrieve the settings of a specific model, there are 3 ways so you can use the one that you like.

1// Way 1
2// Returns string|null
3$user->settings->notifiable;
4 
5// Way 2
6// Returns string|null
7$user->settings->get('multilingual');
8 
9// Way 3
10// Returns Collection
11$data = $user->settings->get(['multilingual', 'notifiable']);
12echo $data->multilingual->value;

# Contributors

MoamenEltouny
15 Contributions