PHP Classes

File: README.md

Recommend this page to a friend!
  Classes of Moamen Eltouny   Laravel Settings Model   README.md   Download  
File: README.md
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: Laravel Settings Model
Store and retrieve settings for model objects
Author: By
Last change:
Date: 4 years ago
Size: 3,540 bytes
 

Contents

Class file image Download

[RaggiTech] Laravel >= 6.0 - Settings/Info.

Latest Stable Version Total Downloads License

Laravel Settings/Info provides a quick and easy methods (General/Model).

Example:

// Create/Update Setting
$page->setSetting('facebook_url', 'https://www.facebook.com/RaggiTech');

// Retrieve Setting's Value
echo $page->setting('facebbok_url');	// https://www.facebook.com/RaggiTech

Install

Install the latest version using Composer:

$ composer require raggitech/laravel-settings

then publish the migration & migrate

$ php artisan vendor:publish --tag=laravel-settings
$ php artisan migrate

Usage

// An Example : (Page Model)
// Using HasSettings in Page Model
...
use RaggiTech\Laravel\Settings\HasSettings;

class Page extends Model
{
    use hasSettings;
...

<a name="gs"></a>

General Settings

<a name="gs_cu"></a>

Create / Update Setting's Value

use RaggiTech\Laravel\Settings\Settings;

// Single
Settings::set('website_status', true);

// Multi
Settings::set([
	'website_status' => false,
	'website_off_message' => 'OFFLINE!',
]);

<a name="gs_get"></a>

Retrieve Value & All

use RaggiTech\Laravel\Settings\Settings;

// Single
$setting = Settings::get('website_keywords'); // raggitech, raggi, ...

// All
$settings = Settings::get(); // => All General Setting

<a name="gs_dc"></a>

Delete & Clear

use RaggiTech\Laravel\Settings\Settings;

// Delete/Remove
Settings::remove('website_keywords');

// Clear
Settings::clear(); // Clearing the general settings

<a name="m"></a>

Model Settings

<a name="m_cu"></a>

Create / Update Setting's Value

// Single
$page->setSetting('status', true);

// Multi
$page->setSettings([
	'website_url'    => 'https://raggitech.com',
	'facebook_url'   => 'https://www.facebook.com/RaggiTech',
	'twitter_url'    => 'https://www.twitter.com/RaggiTech',
	'instagram_url'  => 'https://www.instagram.com/raggitech',
]);

<a name="m_get"></a>

Retrieve Value & All

// Single
$setting = $page->setting('website_url');

// All
$settings = $page->settings;

<a name="gs_dc"></a>

Delete & Clear

// Delete/Remove
$page->removeSetting('instagram_url');

// Clear
$page->clearSettings();// Clearing page's settings

<a name="scopes"></a>

Scopes

// Get every element has no Settings.
$p1 = Page::withoutSettings()->get();

// Get every element has setting (status).
$p2 = Page::withSettings('status')->get();

// Get every element has setting (status == true).
$p3 = Page::withSettingsValue('status', true)->get();

// Get every element has [facebook or twitter or all] settings.
$p4 = Page::withAnySettings(['facebook', 'twitter'])->get();

License

MIT license