在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):anlutro/laravel-settings开源软件地址(OpenSource Url):https://github.com/anlutro/laravel-settings开源编程语言(OpenSource Language):PHP 100.0%开源软件介绍(OpenSource Introduction):Laravel SettingsPersistent, application-wide settings for Laravel. Despite the package name, this package should work with Laravel 4, 5, 6, 7 and 8 (though some versions are not automatically tested). Common problems
Installation - Laravel >= 5.5
Installation - Laravel < 5.5
UsageYou can either access the setting store via its facade or inject it by type-hinting towards the abstract class <?php
Setting::set('foo', 'bar');
Setting::get('foo', 'default value');
Setting::get('nested.element');
Setting::forget('foo');
$settings = Setting::all();
?> Call You could also use the // Get the store instance
setting();
// Get values
setting('foo');
setting('foo.bar');
setting('foo', 'default value');
setting()->get('foo');
// Set values
setting(['foo' => 'bar']);
setting(['foo.bar' => 'baz']);
setting()->set('foo', 'bar');
// Method chaining
setting(['foo' => 'bar'])->save(); Auto-savingIn Laravel 4.x, the library makes sure to auto-save every time the application shuts down if anything has been changed. In Laravel 5.x, if you add the middleware Store cacheWhen reading from the store, you can enable the cache. You can also configure flushing of the cache when writing and configure time to live. Reading will come from the store, and then from the cache, this can reduce load on the store. // Cache usage configurations.
'enableCache' => false,
'forgetCacheByWrite' => true,
'cacheTtl' => 15, JSON storageYou can modify the path used on run-time using Database storageUsing Migration FileIf you use the database store you need to run ExampleFor example, if you want to store settings for multiple users/clients in the same database you can do so by specifying extra columns: <?php
Setting::setExtraColumns(array(
'user_id' => Auth::user()->id
));
?>
If you need more fine-tuned control over which data gets queried, you can use the
<?php
Setting::setConstraint(function($query, $insert) {
if ($insert) return;
$query->where(/* ... */);
});
?> Custom storesThis package uses the Laravel <?php
class MyStore extends anlutro\LaravelSettings\SettingStore {
// ...
}
Setting::extend('mystore', function($app) {
return $app->make('MyStore');
});
?> ContactOpen an issue on GitHub if you have any problems or suggestions. LicenseThe contents of this repository is released under the MIT license. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论