1. Go to this page and download the library: Download bonsaicms/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/ */
// MyModel extends Eloquent
$model = MyModel::first(); // some model instance (not null)
Settings::set('model', $model);
$retrievedModel = Settings::get('model');
Settings::save();
// On the same or on the some future request as well...
$retrievedModel->is($model); // true
use Illuminate\Database\Eloquent\Model as Eloquent;
class MyModel extends Eloquent implements \BonsaiCms\Settings\Contracts\SerializationWrappable
{
use \BonsaiCms\Settings\Models\SerializableModelTrait;
...
interface SerializationWrappable
{
static function wrapBeforeSerialization($wrappable);
static function unwrapAfterSerialization($wrappedClass, $wrappedValue);
}
use BonsaiCms\Settings\Contracts\SerializationWrappable;
class MyClass implements SerializationWrappable
{
/*
* You should map the $wrappable object to some "wrapped value" here and return it.
* The returned value should describe the object so you can re-create it again in the method below.
* This value should be just primitive (string, number, array ...) because it will be serialized
* and persisted in settings repository.
*/
static function wrapBeforeSerialization($wrappable)
{
return [
'something' => 'some-wrapped-value'
];
}
/*
* This method should return the original `$wrappable` passed to method above.
*/
static function unwrapAfterSerialization($wrappedClass, $wrappedValue)
{
/*
* $wrappedClass; // MyClass::class
* $wrappedValue; // ['something' => 'some-wrapped-value']
*/
return new MyClass; // You can pass $wrappedValue to the constructor
}
}
$myObject = new MyClass;
Settings::set('obj', $myObject);
Settings::get('obj'); // same as $myObject (but probably not equal, depends on what you return in `unwrapAfterSerialization` method
Settings::save('obj');
bash2
$ php artisan vendor:publish --tag=settings
bash2
$ php artisan migrate
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.