You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
3.1 KiB

5 years ago
  1. [![Latest Stable Version](https://poser.pugx.org/efriandika/laravel-settings/v/stable.svg)](https://packagist.org/packages/efriandika/laravel-settings)
  2. [![Total Downloads](https://poser.pugx.org/efriandika/laravel-settings/downloads.svg)](https://packagist.org/packages/efriandika/laravel-settings)
  3. [![Latest Unstable Version](https://poser.pugx.org/efriandika/laravel-settings/v/unstable.svg)](https://packagist.org/packages/efriandika/laravel-settings)
  4. [![License](https://poser.pugx.org/efriandika/laravel-settings/license.svg)](https://packagist.org/packages/efriandika/laravel-settings)
  5. # Laravel-Settings
  6. Laravel 5.1.x Persistent Settings (Database + Cache)
  7. ### Attention: for update to v1.2.0
  8. Re-Publish new migration file
  9. $ php artisan vendor:publish --provider="Efriandika\LaravelSettings\SettingsServiceProvider" --force
  10. And run
  11. $ php artisan migrate
  12. ## How to Install
  13. Require this package with composer ([Packagist](https://packagist.org/packages/efriandika/laravel-settings)) using the following command:
  14. composer require efriandika/laravel-settings
  15. or modify your `composer.json`:
  16. "require": {
  17. "efriandika/laravel-settings": "1.*"
  18. }
  19. then run `composer update`:
  20. After updating composer, Register the ServiceProvider to the `providers` array in `config/app.php`
  21. 'Efriandika\LaravelSettings\SettingsServiceProvider',
  22. Add an alias for the facade to `aliases` array in your `config/app.php`
  23. 'Settings' => Efriandika\LaravelSettings\Facades\Settings::class,
  24. Publish the config and migration files now (Attention: This command will not work if you don't follow previous instruction):
  25. $ php artisan vendor:publish --provider="Efriandika\LaravelSettings\SettingsServiceProvider" --force
  26. Change `config/settings.php` according to your needs. If you change `db_table`, don't forget to change the table's name
  27. in the migration file as well.
  28. Create the `settings` table.
  29. $ php artisan migrate
  30. ## How to Use it?
  31. Set a value
  32. Settings::set('key', 'value');
  33. Get a value
  34. $value = Settings::get('key');
  35. Get a value with Default Value.
  36. $value = Settings::get('key', 'Default Value');
  37. > Note: If key is not found (null) in cache or settings table, it will return default value
  38. Get a value via an helper
  39. $value = settings('key');
  40. $value = settings('key', 'default value');
  41. Forget a value
  42. Settings::forget('key');
  43. Forget all values
  44. Settings::flush();
  45. ## Fallback to Laravel Config (available in v1.2.0)
  46. How to activate?
  47. // Change your config/settings.php
  48. 'fallback' => true
  49. Example
  50. /*
  51. * If the value with key => mail.host is not found in cache or DB of Larave Settings
  52. * it will return same value as config::get('mail.host');
  53. */
  54. Settings::get('mail.host');
  55. > Note: It will work if default value in laravel setting is not set
  56. ### Changelogs
  57. v1.2.0 - Dec 16th, 2015
  58. * Bugs fix
  59. * Adding Feature: Fallback Value
  60. ### To Do
  61. -
  62. ### License
  63. The Laravel 5 Persistent Settings is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)