Preface
Introduction
A framework agnostic settings package that allows you to register settings in a more object oriented way in your application.
The package requires PHP 7.3+ and comes bundled with a Laravel 8 Service Provider to simplify the optional framework integration and follows the FIG standard PSR-1, PSR-2 and PSR-4 to ensure a high level of interoperability between shared PHP code and is fully unit-tested.
Have a read through the Installation Guide.
Examples
In this example we'll be covering all the sections of the Settings package, you can read about them on their appropriate sections.
use Cartalyst\Settings\Repository;
$repository = new Repository('app-settings', function ($repository) {
// Assign some attributes
$repository->name = 'Main Application Settings';
$repository->description = 'This is the Main Application Settings.';
// Create a Form
$repository->form('my-application', function ($form) {
$form->name = 'Main Form';
// Create a Form Section
$form->section('general', function ($section) {
$section->name = 'General Settings';
// Create a Fieldset
$section->fieldset('foo', function ($fieldset) {
$fieldset->name = 'Main Form';
// Create a Field
$fieldset->field('my-field', function ($field) {
$field->name = 'My Field';
});
// Create another Field but with Options
$fieldset->field('my-other-field', function ($field) {
$field->name = 'My Other Field';
$field->type = 'checkbox';
// Add an option
$field->option('option-1', function ($option) {
$option->label = 'Option 1';
$option->value = 'option-1';
});
// Add an option
$field->option('option-2', function ($option) {
$option->label = 'Option 2';
$option->value = 'option-2';
});
});
});
});
});
});
Setup
Installation
The best and easiest way to install the Settings package is with Composer.
Preparation
Open your composer.json
file and add the following to the require
array:
"cartalyst/settings": "^5.0"
Add the following lines after the require
array on your composer.json
file:
"repositories": [
{
"type": "composer",
"url": "https://packages.cartalyst.com"
}
]
Note: Make sure that after the required changes your
composer.json
file is valid by runningcomposer validate
.
Install the dependencies
Run Composer to install or update the new requirement.
php composer install
or
php composer update
Now you are able to require the vendor/autoload.php
file to autoload the package.
Integration
Cartalyst packages are framework agnostic and as such can be integrated easily natively or with your favorite framework.
Native
..
Laravel 8
The Settings package has optional support for Laravel 8 and it comes bundled with a Service Provider and a Facade for easy integration.
After installing the package, open your Laravel config file located at config/app.php
and add the following lines.
In the $providers
array add the following service provider for this package.
'Cartalyst\Settings\Laravel\SettingsServiceProvider',