PHP code example of cklmercer / laravel-model-settings
1. Go to this page and download the library: Download cklmercer/laravel-model-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/ */
cklmercer / laravel-model-settings example snippets
use Cklmercer\ModelSettings\HasSettings;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use HasSettings;
// truncated for brevity..
}
$user = App\User::first();
$user->settings()->all(); // Returns an array of the user's settings.
$user->settings()->get(); // Returns an array of the user's settings.
$user = App\User::first();
$user->settings()->get('some.setting');
$user->settings()->get('some.setting', $defaultValue); // With a default value.
$user->settings('some.setting'); // Quicker access.
use Cklmercer\ModelSettings\HasSettings;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use HasSettings;
/**
* The model's default settings.
*
* @var array
*/
protected $defaultSettings = [
'homepage' => '/profile'
];
// truncated for brevity..
}
use Cklmercer\ModelSettings\HasSettings;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use HasSettings;
/**
* The model's allowed settings.
*
* @var array
*/
protected $allowedSettings = ['homepage'];
// truncated for brevity..
}
use Cklmercer\ModelSettings\HasSettings;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use HasSettings;
/**
* 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.