Find the model a setting is for? #81
Unanswered
designvoid
asked this question in
Q&A
Replies: 1 comment
-
I have got it working like this but wondering if there's a nicer way I'm missing? <?php
declare(strict_types=1);
namespace App\Services;
use InvalidArgumentException;
use Rawilk\Settings\Support\Context;
class SettingsService
{
public function decodeContextString(string $serializedString): array
{
$serializedPart = substr($serializedString, strpos($serializedString, 'O:31:'));
$object = unserialize($serializedPart, ['allowed_classes' => true]);
if ($object instanceof Context) {
return $object->toArray();
}
throw new InvalidArgumentException('Failed to unserialize the object.');
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am building some logging and am recording models being saved - when a setting is saved I want to save the id of the model the setting was for - I only have access to the setting model instance - is there a way to pull it from the context in the key? Not sure how to best deconstruct that?
Beta Was this translation helpful? Give feedback.
All reactions