Kalibrant - a package that provides a simple way to manage your models settings

Related tags

Laravel kalibrant
Overview

Logo Kalibrant

Build Status Build Status Build Status Total Downloads Latest Stable Version License

Introduction

For your laravel 9.x applications, Kalibrant is a package that provides a simple way to manage your models settings. It is a simple way to manage your user and team models settings.

Installation

You can install the package via composer:

composer require starfolksoftware/kalibrant

You can publish and run the migrations with:

php artisan vendor:publish --tag="kalibrant-migrations"
php artisan migrate

You can publish the config file with:

php artisan vendor:publish --tag="kalibrant-config"

This is the contents of the published config file:

return [
    /**
     * Define all the settings groups.
     */
    'groups' => [
        // 'setting-group' => SettingGroup::class,
    ],

    'middleware' => ['web'],
];

Usage

Add the HasSetting trait to your model:



namespace App\Models;

use StarfolkSoftware\Kalibrant\HasSettings;

class User extends Authenticatable
{
    use HasSetting;
}

You can create a new setting file by running the following command from the terminal:

php artisan make:setting AutopilotSettings

This is will create a new file in the /app/Settings/ directory. Here is a sample file:



namespace App\Settings;

use App\Models\User;
use StarfolkSoftware\Kalibrant\Settings;
use Symfony\Component\OptionsResolver\OptionsResolver;

class AutopilotSettings extends Settings
{
    /**
     * The route to redirect to after update.
     * 
     * @var mixed
     */
    public $redirectRoute = 'profile.show';

    /**
     * Constructor.
     *
     * @param mixed $id
     * @return void
     */
    public function __construct(
        protected $id
    )
    {
        parent::__construct();
    }

    /**
     * Configure the settings attributes
     * 
     * @param OptionsResolver $resolver
     * 
     * @return void
     */
    public function configureAttributes(OptionsResolver $resolver)
    {
        $resolver->define('enabled')
            ->default(false)
            ->allowedTypes('boolean')
            ->info('Whether autopilot is enabled');
        
        $resolver->define('channels')
            ->default(['twitter'])
            ->allowedTypes('array')
            ->info('The channels to autopilot');

        $resolver->define('tweet_freq')
           ->default(60)
           ->allowedTypes('integer', 'string')
           ->info('Tweets count every hour.');

        $resolver->define('retweet_freq')
            ->default(15)
            ->allowedTypes('integer', 'string')
            ->info('Number of retweets in an hour');

        $resolver->define('like_freq')
            ->default(15)
            ->allowedTypes('integer', 'string')
            ->info('Number of likes in an hour');

        $resolver->define('follow_freq')
            ->default(15)
            ->allowedTypes('integer', 'string') 
            ->info('Number of follows in an hour');
            
        $resolver->define('hashtags')
            ->default(['#programming', '#dev'])
            ->allowedTypes('array')
            ->info('Relavant hashtags.');
    }

    /**
     * Returns the setable type
     * 
     * @return string
     */
    public static function setableType()
    {
        return User::class;
    }

    /**
     * Returns the setable id
     * 
     * @return int
     */
    public function setableId()
    {
        return $this->id;
    }

    /**
     * Return the settings group
     * 
     * @return string
     */
    public static function group()
    {
        return 'autopilot-settings';
    }

    /**
     * Validation rules.
     * 
     * @return array
     */
    public function rules(): array
    {
        return [
            'enabled' => ['required', 'boolean'],
            'channels' => ['required', 'array'],
            'channels.*' => ['required', 'string', 'in:twitter,facebook,instagram,linkedin'],
            'tweet_freq' => ['required', 'integer', 'max:12'],
            'retweet_freq' => ['required', 'integer', 'max:12'],
            'like_freq' => ['required', 'integer', 'max:12'],
            'follow_freq' => ['required', 'integer', 'max:12'],
            'hashtags' => ['required', 'array'],
            'hashtags.*' => ['required', 'string'],
        ];
    }
}

To update the settings, make a PUT request to route('settings.update', ['group' => '..', 'id' => '...']) with the defined attributes as data. A sample request to update the above settings:



    $response = $this->putJson(route('settings.update', ['group' => 'autopilot-settings', 'id' => $user->id]), [
        'enabled' => true,
        'channels' => ['twitter', 'facebook'],
        'tweet_freq' => '60',
        'retweet_freq' => '15',
        'like_freq' => '15',
        'follow_freq' => '15',
        'hashtags' => ['#programming', '#dev'],
    ]);

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

You might also like...
Laravel Boilerplate provides a very flexible and extensible way of building your custom Laravel applications.
Laravel Boilerplate provides a very flexible and extensible way of building your custom Laravel applications.

Laravel Boilerplate Project Laravel Boilerplate provides a very flexible and extensible way of building your custom Laravel applications. Table of Con

This package aims to help you standardize all your API responses in a simple and structured way.

Laravel API Response This package aims to help you standardize all your API responses in a simple and structured way. By default, the stucture of the

The package lets you generate TypeScript interfaces from your Laravel models.

Laravel TypeScript The package lets you generate TypeScript interfaces from your Laravel models. Introduction Say you have a model which has several p

A Laravel package making a diagram of your models, relations and the ability to build them with it
A Laravel package making a diagram of your models, relations and the ability to build them with it

Laravel Schematics This package allows you to make multiple diagrams of your Eloquent models and their relations. It will help building them providing

This package allows you to easily work with NanoID in your Laravel models.
This package allows you to easily work with NanoID in your Laravel models.

Laravel Model UUIDs Introduction Huge thanks to Micheal Dyrynda, whose work inspired me to create this package based on laravel-model-nanoid but uses

Persistent settings in Laravel

Laravel Settings Persistent, application-wide settings for Laravel. Despite the package name, this package works with Laravel 4, 5, 6, 7 and 8! Common

Per-user settings repository system for Laravel
Per-user settings repository system for Laravel

Laraconfig Per-user settings repository system for Laravel. This package allows users to have settings that can be queried, changed and even updated,

Store and retrieve settings generally or for model objects in Laravel.
Store and retrieve settings generally or for model objects in Laravel.

Store and retrieve settings generally or for model objects in Laravel. Documentation You can find the detailed documentation here in Laravel Settings

Add settings to any Laravel model.

Laravel Property Bag Simple settings for Laravel apps. Easily give multiple resources settings Simple to add additional settings as your app grows Set

Comments
Releases(v1.0.2)
  • v1.0.2(Mar 19, 2022)

    What's Changed

    • chore: updated readme by @frknasir in https://github.com/starfolksoftware/kalibrant/pull/2

    New Contributors

    • @frknasir made their first contribution in https://github.com/starfolksoftware/kalibrant/pull/2

    Full Changelog: https://github.com/starfolksoftware/kalibrant/compare/v1.0.1...v1.0.2

    Source code(tar.gz)
    Source code(zip)
  • v1.0.1(Mar 19, 2022)

  • v1.0.0(Mar 19, 2022)

Owner
Starfolk
We empower our clients to create innovative digital solutions that can be easily deployed to solve important business problems.
Starfolk
This package gives Eloquent models the ability to manage their friendships.

Laravel 5 Friendships This package gives Eloquent models the ability to manage their friendships. You can easily design a Facebook like Friend System.

Alex Kyriakidis 690 Nov 27, 2022
⚙️Simple key/value typed settings for your Laravel app with synchronized json export

Simple key/value typed settings for your Laravel app Create, store and use key/value settings, typed from numbers over dates to array, cached for quic

elipZis 8 Jan 7, 2023
Otpify is a Laravel package that provides a simple and elegant way to generate and validate one time passwords.

Laravel Otpify ?? Introduction Otpify is a Laravel package that provides a simple and elegant way to generate and validate one time passwords. Install

Prasanth Jayakumar 2 Sep 2, 2022
A Laravel package to manage versions of endpoints in an elegant way

API version control A Laravel package to manage versions of endpoints in an elegant way Two ways to manage the versions of your endpoints Option 1: Ve

Reindert 156 Dec 9, 2022
Simple Arabic Laravel Dashboard , has basic settings and a nice layout . to make it easy for you to create fast dashboard

Simple Arabic Laravel Dashboard ✅ Auto Seo ✅ Optimized Notifications With Images ✅ Smart Alerts ✅ Auto Js Validations ✅ Front End Alert ✅ Nice Image V

Peter Tharwat 254 Dec 19, 2022
An Eloquent Way To Filter Laravel Models And Their Relationships

Eloquent Filter An Eloquent way to filter Eloquent Models and their relationships Introduction Lets say we want to return a list of users filtered by

Eric Tucker 1.5k Jan 7, 2023
🏭 An easy way to generate populated factories for models.

Laravel Populated Factory provides an easy way to generate populated factories for models according to types & names of their columns. Install You can

Coderello 241 Nov 25, 2022
An Eloquent Way To Filter Laravel Models And Their Relationships

Eloquent Filter An Eloquent way to filter Eloquent Models and their relationships Introduction Lets say we want to return a list of users filtered by

Eric Tucker 1.5k Dec 30, 2022
Model Settings for your Laravel app

Model Settings for your Laravel app The package requires PHP 7.3+ and follows the FIG standards PSR-1, PSR-2, PSR-4 and PSR-12 to ensure a high level

Lorand Gombos 611 Dec 15, 2022
Store your Laravel application settings in an on-disk JSON file

Store your Laravel application settings in an on-disk JSON file. This package provides a simple SettingsRepository class that can be used to store you

Ryan Chandler 24 Nov 16, 2022