PHP code example of tatter / preferences

1. Go to this page and download the library: Download tatter/preferences 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/ */

    

tatter / preferences example snippets


class Home extends Controller
{
    public function index()
    {
        return view('welcome', [
            'icon' => preference('Users.avatar'),
        ];
    }

    public function update_avatar()
    {
        if ($icon = $this->request->getPost('icon')) {
            preference('Users.avatar', $icon);
        }

        return redirect()->back();
    }
}



namespace Config;

class Preferences extends \Tatter\Preferences\Config\Preferences
{
    /**
     * Slug for the current user theme.
     */
    public string $theme = 'midnight';
}

// Identical calls:
$theme = preference('Preferences.theme');
$theme = preference('theme');