PHP code example of twom / laravel-setting

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

    

twom / laravel-setting example snippets


//	Single item
Setting::set("key", "value");
Setting::get("key", "default_value");
Setting::forget("key");

//	Multiple items
Setting::set(["one" => "value", "some" => "any..."]);
Setting::get(["one", "some"]);
Setting::forget(["key", "key-2"]);

Setting::all();

// string
Setting::set("profile.notification.email", true);

// array
Setting::set([
	"profile" => [
		"notification" => [
			"sms" => true // or any value
		]
	], 
]);

//	get string
Setting::get("profile.notification.email", "default");

//	result should be an array
Setting::get("profile");
  
namespace App;  
  
use Illuminate\Database\Eloquent\Model;  
use Twom\Setting\Support\Settingable;  
  
class Post extends Model  
{  
  use Settingable;  
  
  public $timestamps = false;  
  
  protected $fillable = [  
	  'title', // and another fields
  ];  
}

$post = Post::find(1);

//	Just like normaliza
$post->setSetting("key", "value");
$post->getSetting("key", "default");
$post->forgetSetting("key");
$post->getAllSetting();
 php
'providers' => [
	 // for laravel 5.8 and below
	 \Twom\Taggable\SettingServiceProvider::class,
];