PHP code example of elnooronline / laravel-settings
1. Go to this page and download the library: Download elnooronline/laravel-settings 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/ */
Setting::get('name', 'Computer');
// get setting value with key 'name'
// return 'Computer' if the key does not exists
Setting::all();
// get all settings
Setting::lang('en')->get('name', 'Computer');
// get setting value with key and language
Setting::get('name:en', 'Computer');
// get setting value with key and language
Setting::set('name', 'Computer');
// set setting value by key
Setting::lang('en')->set('name', 'Computer');
// set setting value by key and language
Setting::set('name:en', 'Computer');
// set setting value by key and language
Setting::has('name');
// check the key exists, return boolean
Setting::lang('en')->has('name');
// check the key exists by language, return boolean
Setting::has('name:en');
// check the key exists by language, return boolean
Setting::forget('name');
// delete the setting by key
Setting::lang('en')->forget('name');
// delete the setting by key and language
Setting::forget('name:en');
// delete the setting by key and language
public function boot()
{
Setting::registerPrefixMethod('country');
...
}
return [
/**
* The model of the settings table.
* if you want to override the model you should extend your settings model from the package model class.
*
* 'model_class' => \App\CustomSetting::class,
*
* class CustomSetting extends \Elnooronline\LaravelSettings\Models\SettingModel
* {
* ...
* }
*/
'model_class' => \Elnooronline\LaravelSettings\Models\SettingModel::class,
/**
* The registered prefix methods.
* Ex:
* 'prefix_methods' => [
* 'country'
* ],
* Usage:
* Setting::country('us')->set('title', 'Website')
*/
'prefix_methods' => [
//
],
];
Setting::country('us')->set('title', 'Example Website');
Setting::get('name');
// return return 'Example Website';
Setting::country('eg')->set('title', 'عنوان الموقع');
Setting::country('eg')->get('name');
// return return 'عنوان الموقع';
Setting::country('eg')->forget('name');
// delete the setting by key and country
namespace App;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Elnooronline\LaravelSettings\Models\Traits\HasSettings;
class User extends Authenticatable
{
use HasSettings;
...
}
$user->settings()->set('key', 'value');
$user->settings()->get('key', 'value');
// Or
Seeting::for($user)->set('key', 'value');
Seeting::for($user)->set('key', 'value');