Download the PHP package toneflix-code/laravel-dbconfig without Composer
On this page you can find all versions of the php package toneflix-code/laravel-dbconfig. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download toneflix-code/laravel-dbconfig
More information about toneflix-code/laravel-dbconfig
Files in toneflix-code/laravel-dbconfig
Package laravel-dbconfig
Short Description A Laravel package that allows you to configure your app using database entries with support for Arrays and files.
License MIT
Homepage https://github.com/toneflix/laravel-dbconfig
Informations about the package laravel-dbconfig
Laravel DbConfig (Database Configuration)
A Laravel package that allows you to configure your app using database entries with support for Arrays and files.
Features
- Support for single and multiple file uploads.
- Has
dbconfig()
helper function. - Support for custom tables.
- Create configurations with
php artisan dbconfig:create
command. - Support for Arrays.
- Configurations can be dbconfig:d.
- Update config with
php artisan dbconfig:set
command.
Installation
You can install the package via composer:
Package Discovery
Laravel automatically discovers and publishes service providers but optionally after you have installed Laravel Fileable, open your Laravel config file if you use Laravel below 11, config/app.php
and add the following lines.
In the $providers array add the service providers for this package.
If you use Laravel >= 11, open your bootstrap/providers.php
and the above line to the array.
Asset Publishing
To customize migrations, publish the migration files with:
To customize configuration options, publish the config file with:
Custom Tables
If you need to customize the names of the tables used, edit the table
property of the laravel-dbconfig
configuration file, setting the table names according to your requirement.
Migration
Once you're doing with initial setup, run php artisan migrate
to migrate your database, when you have done this, then the library is ready for use.
Usage
Creating Configuration Options
Artisan Command
To create configuration options from the CLI you can use the dbconfig:create Artisan command
Database seeding
If you have multple options and do not want to add them one after the other, you can publish the factory
and seeder
then modify the seeder, adding in all the option you require in the array and seeding your database as usual.
- Publish
factory
andseeder
by runningphp artisan vendor:publish --tag dbconfig-data
. - Modify seeder.
- Seed your database by running
php artisan db:seed ConfigurationSeeder
.
Accessing configuration
To access your saved configuration, you can call the config
helper method on the Configure
class.
Or use the flat helper function.
Accessing all configuration option
If you do not provide a key when calling Configure::config()
or dbconfig()
an instance of Illuminate\Support\Collection
will be returned with all available configuration options as [key => value] pair collection.
Or
Updating Configurations
Passing an array to the dbconfig
function or the config
method will imply that you want to update the configuration option.
Or
In either case, the calls will return an instance of \Illuminate\Support\Collection
with the current state of the config.
Supported Data types
When creating configuration options, you will be required to provide a value for the type
attribute, which is used to determine what kind of data to expect from the config value
.
This library supports the following data types as values:
string
bool
int
float
json
file
For convinience and in order to provide flexibility, we will also map the following type
config values to their applicable data types:
- [
textarea
,text
]:string
- [
number
,integer
]:int
- [
boolean
]:bool
- [
file
]: array offile
- The
json
data type will automatically be wrapped with an\Illuminate\Support\Collection
instance.
Secret Data
When creating your options, if you set the secret
attribute to true
, the value will automatically be masked whenever it is accessed.
To allow secret values to be visible, when you call the Configure::config()
or dbconfig()
methods, set the loadSecret
argument to true, this will ensure that, even secret values are visible.
Or
Files
Configuration options of type
file
will be uploaded to your configured storage driver and a direct link to the file will be generated and passed as the configuration value
.
Whe the configuration type is files
, the files will be uploaded and you will get an \Illuminate\Support\Collection
of direct link urls to all the uploaded files.
Storage path
The library uses toneflix-code/laravel-fileable
for storing files, you can configure the upload path and othe options by modifying the upload_collection
property of the laravel-dbconfig
configuration file or add a dbconfig
collection to the toneflix-fileable
configuration.
Saving configuration with file values
To save a configuration with a file value, simply pass an instance of Illuminate\Http\UploadedFile
as a value when setting the configuration, the lirary takes care of the rest.
Or
Artisan Commands
The library ships with 4 artisan commands provided to to make working with the library a little bit less straining, maybe, but let's get to it.
dbconfig:create
The dbconfig:create
command allows you to create new configuration options, to use, run it like in the examples below.
You will be presented with interactive questions to help you create your config option, alternatively, you can also pass the option definition directly to the command to create without prompts:
When you run the dbconfig:create
passing all options directly, you will still be required to confirm, where you do not want to to be required to confirm, you can pass the --force
option, which will run the command without prompts.
dbconfig:purge
The dbconfig:purge
command allows you to purge or remove configuration options from the database.
Running the command without arguments will cause the entire configuration table to be truncated but if you wish to only remove a particular key from the table, simply pass the key argument.
dbconfig:set
The dbconfig:set
command allows you to set or update the value of a configuration option.
You will be presented with interactive questions to help you update the value of your config option, alternatively, you can also pass the key and value arguments directly to the command to update without the prompts:
dbconfig:show
The dbconfig:show
command will display all of the values for the database configurations.
Additional
You may also run the php artisan about
command to see usefull information about your confiuration state.
And that's it folks, happy coding...
Testing
Changelog
Please see CHANGELOG for more information what has changed recently.
TODO
- [x] Add dbconfig: status to about command.
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
- Toneflix Code
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-dbconfig with dependencies
illuminate/support Version ^9.0|^10.0|^11.0
toneflix-code/laravel-fileable Version ^2.1.4