PHP code example of starfolksoftware / kalibrant

1. Go to this page and download the library: Download starfolksoftware/kalibrant library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

starfolksoftware / kalibrant example snippets


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

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



namespace App\Models;

use StarfolkSoftware\Kalibrant\HasSettings;

class User extends Authenticatable
{
    use HasSetting;
}



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' => ['



    $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'],
    ]);
bash
php artisan vendor:publish --tag="kalibrant-migrations"
php artisan migrate
bash
php artisan vendor:publish --tag="kalibrant-config"
bash
php artisan make:setting AutopilotSettings