PHP code example of x-laravel / model-settings-bag
1. Go to this page and download the library: Download x-laravel/model-settings-bag 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/ */
use XLaravel\ModelSettingsBag\HasSettingsBag;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use HasSettingsBag;
// truncated for brevity..
}
use XLaravel\ModelSettingsBag\HasSettingsBag;
use Illuminate\Database\Eloquent\Model;
class UserThemeSetting extends Model
{
use HasSettingsBag;
}
class User extends Model
{
use HasSettingsBag;
public function themeSettings()
{
return $this->hasOne(UserThemeSetting::class);
}
}
$user = App\User::first();
$user->settings()->all(); // Returns an array of the user's settings.
$user->settings('theme')->get(); // Returns an array of a user's theme settings.
$user = App\User::first();
$user->settings()->get('some.setting');
$user->settings()->get('some.setting', $defaultValue); // With a default value.
$user->settings('theme')->get('layout.boxed');
$user->settings('theme')->get('layout.boxed', $defaultValue); // With a default value.
use XLaravel\ModelSettingsBag\HasSettingsBag;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use HasSettingsBag;
/**
* The model's default settings.
*
* @var array
*/
protected $defaultSettings = [
'homepage' => '/profile'
];
// truncated for brevity..
}
use XLaravel\ModelSettingsBag\HasSettingsBag;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use HasSettingsBag;
/**
* The model's allowed settings.
*
* @var array
*/
protected $allowedSettings = ['homepage'];
// truncated for brevity..
}
use XLaravel\ModelSettingsBag\HasSettingsBag;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use HasSettingsBag;
/**
* The settings field name.
*
* @var string
*/
protected $mapSettingsTo = 'config';
// truncated for brevity..
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.