Package Data | |
---|---|
Maintainer Username: | aboudeh87 |
Maintainer Contact: | aboudeh1987@gmail.com (Abdulkader Zeineddin) |
Package Create Date: | 2016-09-07 |
Package Last Update: | 2023-11-13 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-12-23 03:29:22 |
Package Statistics | |
---|---|
Total Downloads: | 4,877 |
Monthly Downloads: | 71 |
Daily Downloads: | 4 |
Total Stars: | 3 |
Total Watchers: | 3 |
Total Forks: | 0 |
Total Open Issues: | 0 |
This package to generate a preferences page to the application, specially if you have many component that have a different settings and you want to store it in the database and use it by default config functions of laravel.
composer require geniusts/preferences
{
"require": {
"geniusts/preferences": "~1.1.0"
}
}
and run:
composer update
auto-discover
is enabled, no need to do anything.auto-discover
add the ServiceProvider to the providers array in config/app.php
GeniusTS\Preferences\PreferencesServiceProvider::class,
Note: If you are using Laravel 5.5 or greater no need to add it, It will auto discove
Publish the package Controller file to your application. Run these commands:
php artisan vendor:publish --provider="GeniusTS\Preferences\PreferencesServiceProvider" --tag=controller
You can also publish views and migrations by the following commands:
php artisan vendor:publish --provider="GeniusTS\Preferences\PreferencesServiceProvider" --tag=views
php artisan vendor:publish --provider="GeniusTS\Preferences\PreferencesServiceProvider" --tag=migrations
No need to publish the migrations files just run migrate command to execute the migrations.
php artisan migrate
If you want to use
DB
transaction while saving the data, addprotected $transactions = true;
toSettingsController
Add two routes to you routes file:
Route::get('/settings', 'SettingsController@edit')
->midllware(//Apply your middleware)
Route::patch('/settings', 'SettingsController@update')
->midllware(//Apply your middleware)
Now you have to create a preferences.settings
view with your app layout
and include the geniusts_preferences::settings
view.
@include('geniusts_preferences::settings');
settings/general.blade.php
<div class="row">
<div class="col-xs-12">
<div class="form-group">
<label> Test </label>
<div class="input-group">
<div class="input-group-addon">
<i class="glyphicon glyphicon-alert"></i>
</div>
<input class="form-control"
name="project_name"
value="{{ old('project_name', config('preferences.general.project_name')) }}">
</div>
</div>
</div>
</div>
use GeniusTS\Preferences\Models\Domain;
use GeniusTS\Preferences\Models\Element;
// Create a settings Domain
// Domain(string $key, View $view, string $label)
// you can use label like 'labels.general', because the view execute "trans" function
$domain = new Domain('general', view('settings.general'), 'General');
// Add the inputs names and validation rules
// Element(string $name, mixed $rules)
$domain->addElement(new Element('project_name', 'required|max:255'));
// OR for array values
$domain->addElement(new Element('options', ['options' => 'array', 'options.*' => 'required|integer']));
// register the Domain to the Preferences manager
$manager = resolve('preferences'); // or app('preferences') for versions older than 5.3
$manager->addDomain($domain);
You can register the
domains
in theboot
function of your package service provider.
Use the default config
function or Config
class to get the values of
your settings: config('preferences.{domain}.{element}')
config('preferences.general.project_name');
This package is free software distributed under the terms of the MIT license.