Package Data | |
---|---|
Maintainer Username: | it-devgroup |
Maintainer Contact: | gavoronok30@gmail.com (Gavoronok30) |
Package Create Date: | 2021-05-11 |
Package Last Update: | 2023-02-16 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-04-26 03:00:34 |
Package Statistics | |
---|---|
Total Downloads: | 318 |
Monthly Downloads: | 1 |
Daily Downloads: | 0 |
Total Stars: | 0 |
Total Watchers: | 3 |
Total Forks: | 0 |
Total Open Issues: | 0 |
1. Open file bootstrap/app.php
Uncommented strings
$app->withFacades();
$app->withEloquent();
Added after $app->configure('app');
$app->configure('setting_lite');
add new service provider
$app->register(\ItDevgroup\LaravelSettingLite\Providers\SettingServiceProvider::class);
2. Run commands
For creating config file
php artisan setting:publish --tag=config
For creating migration file
php artisan setting:publish --tag=migration
For generate table
php artisan migrate
1. Open file config/app.php and search
'providers' => [
...
]
Add to section
\ItDevgroup\LaravelSettingLite\Providers\SettingServiceProvider::class,
Example
'providers' => [
...
\ItDevgroup\LaravelSettingLite\Providers\SettingServiceProvider::class,
]
2. Run commands
For creating config file
php artisan vendor:publish --provider="ItDevgroup\LaravelSettingLite\Providers\SettingServiceProvider" --tag=config
For creating migration file
php artisan setting:publish --tag=migration
For generate table
php artisan migrate
1. Create seeder file if not exists for settings.
In the created seed file, you need to add a static method (for example, public static function data()
).
The method must return an array of standard to fill the database
2. Open config file config/setting_lite.php
and add this class and method in exists parameters
'data' => [
'class' => SettingTableSeeder::class,
'method' => 'data',
],
php artisan setting:sync
Create custom model for setting
Example:
File: app/CustomFile.php
Content:
<?php
namespace App;
class CustomFile extends \ItDevgroup\LaravelSettingLite\Model\Setting
{
}
If need change table name or need added other code:
<?php
namespace App;
class CustomFile extends \ItDevgroup\LaravelSettingLite\Model\Setting
{
protected $table = 'YOUR_TABLE_NAME';
// other code
}
Open config/setting_lite.php and change parameter "model", example:
...
// replace
'model' => \ItDevgroup\LaravelSettingLite\Model\Setting::class,
// to
'model' => \App\CustomFile::class,
Use custom \App\CustomFile model everywhere instead of standard model \ItDevgroup\LaravelSettingLite\Model\Setting
Usage function for get setting value
setting('SETTING_KEY', 'DEFAULT VALUE IF EMPTY SETTING VALUE')
$service = app(\ItDevgroup\LaravelSettingLite\SettingServiceInterface::class);
or injected
// use
use ItDevgroup\LaravelSettingLite\SettingServiceInterface;
// constructor
public function __construct(
SettingServiceInterface $settingService
)
further we will use the variable $service
$array = $service->getTypes();
Only saved groups from table of settings
$array = $service->getGroups();
All settings
$eloquentCollection = $service->getList();
Settings with filter. All filter parameters not required
$filter = (new \ItDevgroup\LaravelSettingLite\Model\SettingFilter())
->setIsPublic(true);
// or
$filter = (new \ItDevgroup\LaravelSettingLite\Model\SettingFilter())
->setKey('partial_key_name')
->setType('type_name')
->setGroup('group_name')
->setIsPublic(true);
$eloquentCollection = $service->getList($filter);
Settings with sorting
$eloquentCollection = $service->getList(null, $fieldName, $ascOrDesc);
$eloquentCollection = $service->getList(null, 'key', 'ASC');
$setting = $service->getById(1);
$setting = $service->getByKey('SETTING_KEY');
$setting = \ItDevgroup\LaravelSettingLite\Model\Setting::register(
'key_1',
'test value',
'text',
'Test'
);
$setting->options = ['val1', 'val2'];
$setting->is_public = true;
$service->createModel($setting);
$setting = $service->getById(1);
$setting->value = 'test value';
$setting->options = ['val1', 'val2'];
$setting->is_public = true;
$service->updateModel($setting);
$setting = $service->getById(1);
$service->deleteModel($setting);
For test need phpunit
vendor/bin/phpunit vendor/it-devgroup/laravel-setting-lite