damodar-bhattarai / settings
Package to store and get general website settings on the fly.
Installs: 1 666
Dependents: 0
Suggesters: 0
Security: 0
Stars: 31
Watchers: 1
Forks: 1
Open Issues: 0
README
Store general settings like website name, logo url, contacts in the database easily. Everything is cached, so no extra query is done. You can also get fresh values from the database directly if you need.
Installation
Install the package via composer
composer require damodar-bhattarai/settings
Publish the migrations using the following command
php artisan vendor:publish --provider="DamodarBhattarai\Settings\SettingsServiceProvider"
Migrate the database
php artisan migrate
I have also added seeder for some general settings a website needs. Seed the database using command:
php artisan db:seed --class=SettingsSeeder
Usage/Examples
To store settings on database
settings()->set('key','value');
You can also set multiple settings at once
settings()->set([
'key1'=>'value1',
'key2'=>'value2',
'key3'=>'value3'
]);
You can retrieve the settings from cache using any command below
settings('key');
settings()->get('key');
You can provide default value to key if that key doesn't exist
settings('key','default'); //returns default
settings()->get('key','default'); //returns default
Want the settings directly from database? You can do it,
settings('key','default',true);
settings()->get('key','default',true);
Getting all the settings stored on database
settings()->getAll();
Lets see some examples:
set "site_name" as "StillAlive"
settings()->set('site_name','StillAlive');
get "site_name" value
settings('site_name'); //outputs StillAlive
set multiple settings
settings()->set([
'site_name'=>'StillAlive',
'email'=>'info@bdamodar.com.np'
'footer_text'=>'Copyright ©',
]);
You can use the settings on blade as
{{ settings('site_name') }}
{{ settings('site_name','default value' )}}
Or, if you have html stored on settings
{!! settings('footer_text') !!}
{!! settings('footer_text',Copyright Date('Y')) !!}
New on v1.0.1 ( short_text helper)
short_text eliminates all the html entities including
so you get clean text from the html provided.
short_text($text, $length = 30, $read_more = false, $link = false, $style = '')
where, $text is html (like from rich text editors)
$length is character limit
$read_more is boolean which helps to show or hide read more link
$link is the link to the above read_more link
$style can be used to add styles and classes like ($style='style="color:blue;" class="font-weight-bold"';)
##example
{{ short_text($post->description,100,true,route('post.show',$post->id),'class="text-red-500"') }}
Finally, If you have changed something directly on database, Don't forget to clear the cache.
php artisan cache:clear
License
Feedback
If you have any feedback, please reach out at damodar.bhattarai.1999@gmail.com or submit a pull request here.