PHP code example of larapacks / setting
1. Go to this page and download the library: Download larapacks/setting library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
larapacks / setting example snippets
php artisan vendor:publish --tag="setting"
Setting::set('key', 'value');
Setting::set([
'key.1' => 'value',
'key.2' => 'value',
'key.3' => 'value',
]);
$value = Setting::get('key.1');
dd($value); // Returns 'value'
$value = Setting::get('non-existent-key', 'default');
dd($value); // Returns 'default'
$model = Setting::find('key.1');
dd($model); // Reurns instance of Model (your configured model).
Setting::set([
'key.1' => 'value',
'key.2' => 'value',
'key.3' => 'value',
]);
$settings = Setting::all();
dd($settings);
// Returns:
// array [
// 'key.1' => 'value',
// 'key.2' => 'value',
// 'key.3' => 'value',
// ]
$model = Setting::model();
$setting = new $model();
$setting->key = 'key';
$setting->value = 'value';
$setting->save();
if (Setting::has('key')) {
// The setting exists.
}
Setting::set('notifications', true);
// Disable notifications.
Setting::flip('notifications');
dd(Setting::get('notifications')); // Returns false.
// Enable notifications.
Setting::flip('notifications');
dd(Setting::get('notifications')); // Returns true.
// Default flip setting:
Setting::flip('new-key');
dd(Setting::get('new-key')); // Retuns true.
Setting::set('notifications', false);
Setting::enable('notifications');
dd(Setting::get('notifications')); // Returns true.
Setting::set('notifications', true);
Setting::disable('notifications');
dd(Setting::get('notifications')); // Returns false.
namespace App;
use Larapacks\Setting\Traits\SettingTrait;
class Setting extends Model
{
use SettingTrait;
}