PHP code example of samchentw / settings

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

    

samchentw / settings example snippets


// routes/web.php

use Samchentw\Settings\Helpers\RouterHelper;

RouterHelper::loadWebRoutes();


    use App\Http\Controllers\Controller;
    use Illuminate\Http\Request;
    use Samchentw\Settings\Contracts\SettingManager;

    class SettingController extends Controller
    {
        private $settingManager;
        public function __construct(SettingManager $SettingManager)
        {
            $this->settingManager = $SettingManager;
        }


        function getSettings(Request $request)
        {
            return $this->settingManager->getByKey('example.title');
        }
    }

    use App\Http\Controllers\Controller;
    use Illuminate\Http\Request;
    use Samchentw\Settings\Contracts\SettingManager;

    class SettingController extends Controller
    {
        private $settingManager;
        public function __construct(SettingManager $SettingManager)
        {
            $this->settingManager = $SettingManager;
        }


        function getSettings(Request $request)
        {
            return $this->settingManager->getByKey('test.boolean');
        }
    }

    $userId= 3 ;
    $this->settingManager->getByKey('example.title','U',$userId);

    $anotherUserId = 4;
    $this->settingManager->setByKey('example.title','使用者自訂標題','U',$anotherUserId);

    $userId= 3 ;
    $this->settingManager->getByFirstWord('social','U',$userId);

   

    use App\YourNameSpace\MySetting;
    use Samchentw\Settings\Contracts\SettingManager;

    class AppServiceProvider extends ServiceProvider
    {

        public function boot()
        {
            app()->singleton(
                SettingManager::class,
                MySetting::class
            );

   

    use Samchentw\Settings\Contracts\SettingManager;
    use Samchentw\Settings\Models\Setting;
    
    class MySetting implements SettingManager
    {

        public function getByKey(string $key, $provider_name = '', $provider_key = null)
        {
            //your code....
        }

    //your code....
sh
$ php artisan migrate