1. Go to this page and download the library: Download rudnev/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/ */
rudnev / laravel-settings example snippets
// app settings:
settings()->set('timezone', 'UTC');
settings()->get('timezone');
// the same:
settings(['timezone' => 'UTC']);
settings('timezone');
// user settings:
settings()->scope($user)->set('lang', 'en');
settings()->scope($user)->get('lang');
namespace App\Http\Controllers;
use Rudnev\Settings\Contracts\RepositoryContract as Settings;
class MyController extends Controller
{
public function index(Settings $settings)
{
$tz = $settings->get('timezone');
}
}
Settings::has('foo');
Settings::get('foo');
// You can specify a default value when an property is null or not found:
Settings::get('foo', 'default');
$user->settings()->set('lang', 'en');
$user->settings()->get('lang');
// the same:
$user->settings(['lang' => 'en']);
$user->settings('lang');
use Rudnev\Settings\Traits\HasSettings;
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
use HasSettings;
protected $settingsConfig = [
'default' => [
'timezone' => 'UTC'
]
];
// ...
}