2017 © Pedro Peláez
 

library preferences

Very easy way to generate a preferences page for applications that have multiple components and packages.

image

geniusts/preferences

Very easy way to generate a preferences page for applications that have multiple components and packages.

  • Monday, May 7, 2018
  • by aboudeh87
  • Repository
  • 1 Watchers
  • 2 Stars
  • 858 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 15 Versions
  • 8 % Grown

The README.md

Preferences page for Laravel

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., (*1)

Installation

  1. Download the package
  • command line:

composer require geniusts/preferences, (*2)

  • or add it to composer file:
{
    "require": {
        "geniusts/preferences": "^2.0"
    }
}

and run: composer update, (*3)

  1. Service Provider
  • If you are using Laravel >=5.5 and the auto-discover is enabled, no need to do anything.
  • If your Laravel <5.5 or you disabled 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, (*4)

  1. Controller And Migrations

Publish the package Controller file to your application. Run these commands:, (*5)

php artisan vendor:publish --provider="GeniusTS\Preferences\PreferencesServiceProvider" --tag=controller

You can also publish views and migrations by the following commands:, (*6)

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., (*7)

php artisan migrate

If you want to use DB transaction while saving the data, add protected $transactions = true; to SettingsController., (*8)

  1. Routes and views

Add two routes to you routes file:, (*9)

Route::get('/settings/{preferences_domain?}', 'SettingsController@edit')
    ->midllware(//Apply your middleware)

Route::patch('/settings/{preferences_domain?}/{preferences_element?}', '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., (*10)

@include('geniusts_preferences::settings');

Usage

Creating settings tab

  1. create a view of the settings: Ex.: 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="general[project_name]"
                           value="{{ old('general.project_name', config('preferences.general.project_name')) }}">
                </div>
            </div>
        </div>
    </div>
  1. Register the tab to PreferencesManager
    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 the boot function of your package service provider., (*11)

Access saved settings

Use the default config function or Config class to get the values of your settings: config('preferences.{domain}.{element}'), (*12)

config('preferences.general.project_name');

Migration from version 1

  1. update inputs name inside preferences views. Ex: You have a general domain that have project_name element, then the input name should be general[project_name]., (*13)

  2. Update declaration of edit and handleSuccessResponse methods of SettingsController inside your project., (*14)

   public function edit($domain = null) {
        // Logic here
   }

    protected function handleSuccessResponse($domain, $element) {
        // Logic here    
    }

License

This package is free software distributed under the terms of the MIT license., (*15)

The Versions

07/05 2018

dev-master

9999999-dev

Very easy way to generate a preferences page for applications that have multiple components and packages.

  Sources   Download

MIT

The Requires

 

by Abdul-Kader Zein-Eddin

laravel settings configurations preferences

27/03 2018

1.1.4

1.1.4.0

Very easy way to generate a preferences page for applications that have multiple components and packages.

  Sources   Download

MIT

The Requires

 

by Abdul-Kader Zein-Eddin

laravel settings configurations preferences

27/11 2017

1.1.3

1.1.3.0

Very easy way to generate a preferences page for applications that have multiple components and packages.

  Sources   Download

MIT

The Requires

 

by Abdul-Kader Zein-Eddin

laravel settings configurations preferences

11/11 2017

1.1.2

1.1.2.0

Very easy way to generate a preferences page for applications that have multiple components and packages.

  Sources   Download

MIT

The Requires

 

by Abdul-Kader Zein-Eddin

laravel settings configurations preferences

05/11 2017

1.1.1

1.1.1.0

Very easy way to generate a preferences page for applications that have multiple components and packages.

  Sources   Download

MIT

The Requires

 

by Abdul-Kader Zein-Eddin

laravel settings configurations preferences

04/11 2017

1.1.0

1.1.0.0

Very easy way to generate a preferences page for applications that have multiple components and packages.

  Sources   Download

MIT

The Requires

 

by Abdul-Kader Zein-Eddin

laravel settings configurations preferences

13/08 2017

1.0.8

1.0.8.0

Very easy way to generate a preferences page for applications that have multiple components and packages.

  Sources   Download

MIT

The Requires

 

by Abdul-Kader Zein-Eddin

laravel settings configurations preferences

11/07 2017

1.0.7

1.0.7.0

Very easy way to generate a preferences page for applications that have multiple components and packages.

  Sources   Download

MIT

The Requires

 

by Abdul-Kader Zein-Eddin

laravel settings configurations preferences

08/01 2017

1.0.6

1.0.6.0

Very easy way to generate a preferences page for applications that have multiple components and packages.

  Sources   Download

MIT

The Requires

 

by Abdul-Kader Zein-Eddin

laravel settings configurations preferences

04/10 2016

1.0.5

1.0.5.0

Very easy way to generate a preferences page for applications that have multiple components and packages.

  Sources   Download

MIT

The Requires

 

by Abdul-Kader Zein-Eddin

laravel settings configurations preferences

29/09 2016

1.0.4

1.0.4.0

Very easy way to generate a preferences page for applications that have multiple components and packages.

  Sources   Download

MIT

The Requires

 

by Abdul-Kader Zein-Eddin

laravel settings configurations preferences

11/09 2016

1.0.3

1.0.3.0

Very easy way to generate a preferences page for applications that have multiple components and packages.

  Sources   Download

MIT

The Requires

 

by Abdul-Kader Zein-Eddin

laravel settings configurations preferences

10/09 2016

1.0.2

1.0.2.0

Very easy way to generate a preferences page for applications that have multiple components and packages.

  Sources   Download

MIT

The Requires

 

by Abdul-Kader Zein-Eddin

laravel settings configurations preferences

09/09 2016

1.0.1

1.0.1.0

Very easy way to generate a preferences page for applications that have multiple components and packages.

  Sources   Download

MIT

The Requires

 

by Abdul-Kader Zein-Eddin

laravel settings configurations preferences

09/09 2016

1.0

1.0.0.0

  Sources   Download

The Requires

 

by Abdul-Kader Zein-Eddin