angus-dv / laravel-setting
Laravel 持久化设置。
dev-main
2022-01-31 05:58 UTC
This package is auto-updated.
Last update: 2024-09-29 05:57:06 UTC
README
此包简化了存储和检索一些零散值的过程。存储的值以json文件的形式保存。
Supoort Laravel 8 and PHP 8
可以使用以下方式使用
settings('key'); // Returns 'value' settings()->get('key'); // Returns 'value' settings()->has('key'); // Returns true // Specify a default value for when the specified key does not exist settings()->get('non existing key', 'default') // Returns 'default' settings()->put('anotherKey', 'anotherValue'); settings('anotherKey', 'anotherValue'); settings(['anotherKey'=> 'anotherValue']); // Put multiple items in one go settings()->put(['ringo' => 'drums', 'paul' => 'bass']); settings()->all(); // Returns an array with all items settings()->forget('key'); // Removes the item settings()->flush(); // Empty the entire valuestore settings()->flushStartingWith('somekey'); // remove all items whose keys start with "somekey" settings()->increment('number'); // settings()->get('number') will return 1 settings()->increment('number'); // settings()->get('number') will return 2 settings()->increment('number', 3); // settings()->get('number') will return 5
安装
您可以通过composer安装此包
composer require angus-dv/laravel-setting
并注册服务提供者
'providers' => [
AngusDV\LaravelSetting\LaravelSettingServiceProvider::class,
],
并运行迁移以创建数据库表
php artisan migrate
使用方法
您可以在settings()上调用以下方法
put
/** * Put a value in the store. * * @param string|array $name * @param string|int|null $value * * @return $this */ public function put($name, $value = null)
get
/** * Get a value from the store. * * @param string $name * * @return null|string */ public function get(string $name)
has
/* * Determine if the store has a value for the given name. */ public function has(string $name) : bool
all
/** * Get all values from the store. * * @return array */ public function all() : array
allStartingWith
/** * Get all values from the store which keys start with the given string. * * @param string $startingWith * * @return array */ public function allStartingWith(string $startingWith = '') : array
forget
/** * Forget a value from the store. * * @param string $key * * @return $this */ public function forget(string $key)
flush
/** * Flush all values from the store. * * @return $this */ public function flush()
flushStartingWith
/** * Flush all values from the store which keys start with the specified value. * * @param string $startingWith * * @return $this */ public function flushStartingWith(string $startingWith)
pull
/** * Get and forget a value from the store. * * @param string $name * * @return null|string */ public function pull(string $name)
increment
/** * Increment a value from the store. * * @param string $name * @param int $by * * @return int|null|string */ public function increment(string $name, int $by = 1)
decrement
/** * Decrement a value from the store. * * @param string $name * @param int $by * * @return int|null|string */ public function decrement(string $name, int $by = 1)
push
/** * Push a new value into an array. * * @param string $name * @param $pushValue * * @return $this */ public function push(string $name, $pushValue)
prepend
/** * Prepend a new value into an array. * * @param string $name * @param $prependValue * * @return $this */ public function prepend(string $name, $prependValue)
count
/** * Count elements. * * @return int */ public function count()
测试
$ composer test
安全
如果您发现任何安全相关问题,请通过电子邮件 hsmsender1370@gmail.com 联系我们,而不是使用问题跟踪器。
许可证
MIT许可证 (MIT)