alexusmai/easy-settings

Laravel + Vue - easy settings for your application

v1.2.3 2019-03-04 16:26 UTC

This package is auto-updated.

Last update: 2024-12-05 05:03:40 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License

Easy Settings Vue App

The application is designed for convenient and fast work with simple data of your application.

For example, you need to place a phone number in the footer of your site. You can enter it directly into the HTML code, but if you need to change it, you'll have to dig into the code. And if you make a website to a client, then he will not even know how to change this number. Of course you can write your own CRUD's for all items ... or you can just use this package.

This package is suitable for storing such data as:

  • strings
  • numbers, phone numbers,
  • small blocks of text
  • Boolean types (true, false) ON / OFF

Also, if you have a multilingual site, then you will also be able to make your work easier, and save the required data in several languages.

Installation

Composer

composer require alexusmai/easy-settings

If you have Laravel 5.4 or earlier version, then add service provider to config/app.php and

Alexusmai\EasySettings\EasySettingsServiceProvider::class,

add alias.

'ESettings' => Alexusmai\EasySettings\Facades\EasySettingsFacade::class,

Publish config file (easy-settings.php)

php artisan vendor:publish --tag=easy-settings-config

You can install npm package directly and use it in your vue application - more information about it - laravel-vue-easy-settings

OR

Publish js and css files - laravel-vue-easy-settings package (compiled, minimised)

php artisan vendor:publish --tag=easy-settings-assets

Run migration -> this command create "easy-settings" table

php artisan migrate

Settings

Open configuration file - config/easy-settings.php

/**
     * List of languages
     * add the necessary ones to create additional fields(field type "Lang")
     */
    'languages'     => ['en', 'ru'],

    /**
     * Development mode
     * Show - edit/add settings group
     */
    'dev'           => true,

    /**
     * Save data to laravel cache
     * set null, 0 - if you don't need cache (default)
     * if you want use cache - set the number of minutes for which the value should be cached
     */
    'cache'         => null,

    /**
     * Middleware
     * Add your middleware name to array -> ['web', 'auth', 'admin']
     * !!!! RESTRICT ACCESS FOR NON ADMIN USERS !!!!
     */
    'middleware'    => ['web', 'auth']

In 'languages' array you can add the necessary languages

To create and edit groups of settings, you must use the developer mode. After you have added the necessary groups of settings, disable the developer mode if you do not want users to be able to change the structure, validation rules, delete, etc.

Use caching, this will avoid unnecessary queries to the database

Be sure to add your middleware to restrict access to the application

Open the view file where you want to place the application block, and add:

  • add a csrf token to head block if you did not do it before
<!-- CSRF Token -->
<meta name="csrf-token" content="{{ csrf_token() }}">
  • the package uses some styles of Bootstrap 4, if you already use it, then you do not need to connect any styles. Otherwise add -
<link href="{{ asset('vendor/easy-settings/css/esettings.css') }}" rel="stylesheet">
  • add js (laravel-vue-easy-settings)
<script src="{{ asset('vendor/easy-settings/js/esettings.js') }}"></script>
  • add div for application
<div id="easy-settings-app"></div>

Usage

Now it remains to add the necessary settings groups, add fields, validation rules and can be used in your code.

ESettings::get('groupName.settingsName');
ESettings::get('groupName.settingsName', $defaultValue);
  • If you have chosen 'radios' type, the result will be a boolean type (true or false).
  • If "Lang" type is selected, the result will depend on the settings of the language of your application, at the time of the call.
  • If the desired language is not found - will be use fallback locale (see config/app.php) or default value.
'fallback_locale' => 'en',

Seeder

Sometimes you need to roll back the database while developing the project, and the package data will be lost. In order to avoid this, you can run the command

php artisan esettings:seed

That will generate a seeder (EasySettingsSeeder) that will contain your data, and you will need to add it to your seeders list (database/seeds/DatabaseSeeder.php)