Download the PHP package arthurydalgo/laravel-app-settings without Composer
On this page you can find all versions of the php package arthurydalgo/laravel-app-settings. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download arthurydalgo/laravel-app-settings
More information about arthurydalgo/laravel-app-settings
Files in arthurydalgo/laravel-app-settings
Package laravel-app-settings
Short Description A package with UI to store and manage all the settings for your application
License MIT
Homepage https://github.com/qcod/laravel-app-settings
Informations about the package laravel-app-settings
Laravel App Settings
Use qcod/laravel-app-settings
to add settings manager with UI in your Laravel app. It stores settings in the database and by default uses Bootstrap 4 for styling but you can configure it to work with any css system.
All the settings saved in db are cached to improve performance by reducing sql query to zero.
Installation
1 - You can install the package via composer:
2 - If you are installing on Laravel 5.4 or lower you will be needed to manually register Service Provider by adding it in config/app.php
providers array and Facade in aliases arrays.
In Laravel 5.5 or above the service provider automatically get registered and a facade AppSettings::get('app_name')
will be available.
3 - Now you should publish the config file with:
It will create config/app_settings.php
with all the configuration option and way to define your setting inputs divided into sections.
4 - Now run the migration by php artisan migrate
to create the settings table.
Getting Started
First you need to define all the settings you want in our settings page. For example we will need these settings app_name
, from_email
& from_name
. Lets define it in config:
config/app_settings.php
Now if you visit http://yourapp.com/settings
route, you will get the UI with all the settings you defined.
You can change the layout to fit it in with your app design by changing app_settings config:
Next open the resources/views/your_setting.blade.php
and include settings partial where you want to display the settings:
Now yo should be seeing settings page as part of your application with your layout 😎.
Access saved settings
You have setting('app_name', 'default value')
and Facade AppSettings::get('app_name', 'default value')
which you can use to get the stored settings.
Change the url for settings
If your app needs different url to access the settings page you can change from config:
Use Group Setting
Many time you want to store settings in a group. With version 1.1
you can define a group name from your config/app_settings.php
. You have a closer to return the name of group as string
In this case you can have different settings for each user.
Use without UI
If you want to just store the key-value pair into DB and don't want the UI to manage settings for example in API? You should use qcod/laravel-settings package instead. This package uses it under the hood to persist the settings.
If you want to use both UI and settings as key-value pair in DB alongside, for that simply use the helper function setting()
or AppSetting::get('app_name')
to store and retrieve settings from DB. For this, you don't need to define any section and inputs in app_settings.php
config.
When using both UI and settings as a key-value pair, make sure to set 'remove_abandoned_settings' => false
in config/app_settings.php otherwise any undefined input fields will be removed when you save settings from UI.
Here are list of available methods:
Access setting in JavaScript
Many a times these settings needs be accessed from your JavaScript. One way you can do it by just sticking it in your layout blade template as global variable.
With this you will be able to access defined settings in your Vue Component or any JavaScript code.
Input types
Here are all the input types with attributes you can define, but you are free to add your own custom input type if needed.
Every input must have a minimum of
name
,type
&label
attributes.
text, number, email
These are literally the same things with just type change and min
and max
attribute for number type.
'data_type' can be used to cast the input data, it can be
array
,int|integer|number
,boolean|bool
andstring
. In case you need something else you always use Accessor to do it.
textarea
A textarea field is same as text but it has rows
and cols
properties.
select
A select box can be defined with options:
Select options from database
You can also populate select options dynamically. In most cases it will be coming from the database, just use a closure for this:
Note: You can use a closure (anonymous function) for most of the fields on inputs if you need to resolve field value dynamically.
boolean
Boolean is just a radio input group with yes or no option, you can also change it to select by setting options
array:
checkbox
Add a checkbox input
checkbox_group
Add a group of checkboxes
image, file
You can use image
and file
input to upload files. File upload will be automatically handled and old files will be replaced with new.
If you define mutator
on input then its up to you to handle the uploading, you must return the path of uploaded file from mutator to store in settings and deal with old files.
. You don't need to use mutator in most of the cases.
You can define rules
to validate incoming files, either it can be image or any document.
Not using Bootstrap 4
If your app doesn't use Twitter Bootstrap 4 you can easily customize this in app_settings.php to follow your css library like Bulma, Foundatio CSS or any other custom solution:
Customizing app settings views
In some case if your app needs custom views you can publish app settings view and then you can customize every part of the setting fields.
Custom input type
Although this package comes with all the inputs you will need. If you need something which not included you can just define an input in your app settings section and give it a custom type, how about a daterange field type="daterange"
.
Next you will be required to publish the views and add a blade view inside resources/views/vendor/app_settings/fields/
folder and match the name of the field like daterange.blade.php
.
@component('app_settings::input_group', compact('field'))
will add the label
and hint
with error
feedback text.
To use this custom input you should define it in app_settings.php
something like this:
This should render your date range field. You can create any type of fields with this.
Accessor and Mutator
Just like an Eloquent model It allows you to define accessor and mutator on inputs which comes handy when creating custom inputs.
Accessor
An accessor can change the setting value while its accessed, it could be a Closer
or a class with handle($value, $key)
method.
Mutator
A Mutator can change the setting value before it stored in db, same as accessor it could be a Closer
or a class with handle($value, $key)
method.
Using different Controller
In order to use your controller to show and store settings you can do it by changing the app_settings.controller
:
Make sure you have index()
and store(Request $request)
method in your controller.
Config file
Changelog
Please see CHANGELOG for more information on what has changed recently.
Testing
The package contains some integration/smoke tests, set up with Orchestra. The tests can be run via phpunit.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
About QCode.in
QCode.in (https://www.qcode.in) is blog by Saqueib which covers All about Full Stack Web Development.
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-app-settings with dependencies
laravel/framework Version ~5.4.0|~5.5.0|~5.6.0|~5.7.0|~5.8.0|^6.0|^7.0|^8.0
arthurydalgo/laravel-settings Version ^1.1