We noticed you're using an ad blocker

Our website is made possible by displaying online advertisements to our visitors. Please consider supporting us by disabling your ad blocker.

Laravel Option Framework

world cup 2022

FootballDesk

Get update standing EPL, UEFA, LaLiga and more

Get Now

Laravel Option Framework is a complete framework for managing your laravel application's dynamic settings in one place with various supported input types. Options are needed in every dynamic website or web application like making dynamic application title, social media links, header-footer dynamic background colour and etc. In Laravel, we make our necessary application option management tool from scratch. Now the Laravel Option Framework made the task easier. Just add the option configuration and you are ready to go! It'll take care of all your option management stuff.

preview-desktop.png

Features

  • Clean & fresh responsive UI
  • Configurable route
  • Configurable middleware
  • Build-in Option UI
  • Various option type support
  • Laravel validation rules support
  • and more

 

Installation

composer require haruncpi/laravel-option-framework

Now run the command for publishing vendor resources.

php artisan vendor:publish --provider="Haruncpi\LaravelOptionFramework\ServiceProvider"

Run migration

php artisan migrate

or create an options table manually

CREATE TABLE `options` (
  `option_name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `option_value` longtext COLLATE utf8_unicode_ci,
  PRIMARY KEY (`option_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci

 

Usages

With Laravel Option Framework, you can manage your application options in 2 ways.

  1. Automatic generated Option UI
  2. Manual

 

1. Automatic generated Option UI

Add an options.php file in your config directory with your necessary option field configuration.

Demo option configuration.

<?php
// config/options.php

return array(
    array(
        "id" => "general",
        "label" => "General",
        "icon" => "fa-cubes",
        "fields" => array(
            array(
                "type" => "text",
                "id" => "site_name",
                "label" => "Site Name",
                "description" => "Enter your site name",
                "icon" => "fa-globe",
                "validation" => 'required|min:10'
            ),
            array(
                "type" => "text",
                "id" => "site_slogan",
                "label" => "Site Slogan",
                "description" => "Enter site slogan",
                "validation" => 'required'
            ),
            array(
                "type" => "timepicker",
                "id" => "backup_time",
                "label" => "Backup Time",
                "description" => "Set db backup time",
                "validation" => 'required'
            )

        )
    ),
    array(
        "id" => "social",
        "label" => "Social",
        "icon" => "fa-globe",
        "fields" => array(
            array(
                "type" => "text",
                "id" => "fb_link",
                "label" => "Facebook",
                "description" => "Enter facebook link",
                "icon" => "fa-facebook-square"
            ),
            array(
                "type" => "text",
                "id" => "twitter_link",
                "label" => "Twitter",
                "description" => "Enter twitter link",
                "icon" => "fa-twitter-square"
            )
        )
    )
);

Now add it on your route file.

Route::optionRoutes();

After adding this route, you will get UI in example.com/admin/options.

 

Retrieve Value

To retrieve an option value just call getOption('your_option_name')

 

Option Group

Required at least one option group.

id mandatory A unique id without space. Ex: social_links
label mandatory String
icon mandatory font awesome icon name. Ex: fa-globe
fields mandatory An array of options field where each field an array.

Available Fields

  • text
  • textarea
  • switcher
  • editor
  • colorpicker
  • datepicker
  • timepicker
  • datetimepicker
  • dropdown
  • autocomplete
  • radio
  • tag
  • multicheck
  • icon

Important Note

Every field must have type, id, label where
type - Must be a type name from available fields.
id - Must be a unique name without space.
label - A label for the field
validation - Any validation rules your required from Laravel validation rules.

Field: text

array(
    "type"        => "text",
    "id"          => "unique_option_name",
    "label"       => "Option Label Name",
    "description" => "Description",
    "placeholder" => "Placeholder",
    "icon"        => "fa-globe",
    "validation"  => 'required|min:22'
)

Field: textarea

array(
    "type"        => "textarea",
    "id"          => "unique_option_name",
    "label"       => "Option Label Name",
    "description" => "Description",
    "icon"        => "icon",
    "validation"  => 'validation rules'
)

Field: switcher

array(
    "type"        => "switcher",
    "id"          => "unique_option_name",
    "label"       => "Option Label Name",
    "description" => "Description",
    "icon"        => "icon",
    "validation"  => 'validation rules'
)

Field: editor

array(
    "type"        => "editor",
    "id"          => "unique_option_name",
    "label"       => "Option Label Name",
    "description" => "Description",
    "icon"        => "icon",
    "validation"  => 'validation rules'
)

Field: colorpicker

array(
    "type"        => "colorpicker",
    "id"          => "unique_option_name",
    "label"       => "Option Label Name",
    "description" => "Description",
    "icon"        => "icon",
    "validation"  => 'validation rules'
)

Field: datepicker

array(
    "type"        => "datepicker",
    "id"          => "unique_option_name",
    "label"       => "Option Label Name",
    "description" => "Description",
    "icon"        => "icon",
    "validation"  => 'validation rules'
)

Field: timepicker

array(
    "type"        => "timepicker",
    "id"          => "unique_option_name",
    "label"       => "Option Label Name",
    "description" => "Description",
    "icon"        => "icon",
    "validation"  => 'validation rules'
)

Field: datetimepicker

array(
    "type"        => "datetimepicker",
    "id"          => "unique_option_name",
    "label"       => "Option Label Name",
    "description" => "Description",
    "icon"        => "icon",
    "validation"  => 'validation rules'
)

Field: dropdown - from the database table

array(
    "type"        => "dropdown",
    "id"          => "unique_option_name",
    "options"     => "users,id,name",
    "label"       => "Option Label Name",
    "description" => "Description",
    "icon"        => "icon",
    "validation"  => 'validation rules'
)

Field: dropdown - from a simple array

array(
    "type"        => "dropdown",
    "id"          => "unique_option_name",
    "options"     => ["Male"=>"Male","Female"=>"Female"],
    "label"       => "Option Label Name",
    "description" => "Description",
    "icon"        => "icon",
    "validation"  => 'validation rules'
)

Field: autocomplete - from the database table

array(
    "type"        => "autocomplete",
    "id"          => "unique_option_name",
    "options"     => "users,id,name",
    "label"       => "Option Label Name",
    "description" => "Description",
    "icon"        => "icon",
    "validation"  => 'validation rules'
)

Field: radio

array(
    "type"        => "radio",
    "id"          => "unique_option_name",
    "options"     => ["BD", "IND", "PAK", "ENG"],
    "label"       => "Option Label Name",
    "description" => "Description",
    "icon"        => "icon",
    "validation"  => 'validation rules'
)

Field: tag

array(
    "type"        => "tag",
    "id"          => "unique_option_name",
    "label"       => "Option Label Name",
    "description" => "Description",
    "icon"        => "icon",
    "validation"  => 'validation rules'
)

Field: multicheck

array(
    "type"        => "multicheck",
    "id"          => "unique_option_name",
    "options"     => ["Cricket", "Hocky", "Foodball"],
    "label"       => "Option Label Name",
    "description" => "Description",
    "icon"        => "icon",
    "validation"  => 'validation rules'
)

Field: icon

array(
    "type"        => "icon",
    "id"          => "unique_option_name",
    "label"       => "Option Label Name",
    "description" => "Description",
    "icon"        => "icon",
    "validation"  => 'validation rules'
)

 

2. Manual

Manage options in your way and logic with laravel option framework helper functions. In this way, you have to care about all validation, UI making and so on.

 

Helper Functions

Create an option

createOption('site_title','Laravel Article');

Get an option value

getOption('site_title');
// Laravel Article

Checking an option exist

optionExist('site_title');
// true

Update an option

updateOption('site_title','Laravel Article');​
//true

Delete an option

deleteOption('foo');
// true

 

Customization

Laravel option framework gives you the flexibility to change option route path, admin panel route path, custom middleware, default icon, etc. If you need to change these configurations then open the option-framework.php file from the config directory and change what you need to change.

 

Share on




Related Post - Latest Post


Tinkerpad - A minimal Laravel code editor

Laravel Query Log

Laravel Jetstream tutorial

Laravel User Activity

Laravel Breeze - Starting with Laravel has been easy!

Laravel API mailer