By default, Flexible fields expect to be stored in a JSON column. If you need to store data in a different way (e.g., in a separate database table using a HasMany or BelongsToMany relationship), you must implement a custom Resolver.
To create a resolver, use the Artisan command:
php artisan flexible:resolver {classname?}
Each resolver must implement Whitecube\NovaFlexibleContent\Value\ResolverInterface, which requires two methods:
get($resource, $attribute, $layouts): Responsible for retrieving the content and returning a collection of hydrated Layout instances.set($model, $attribute, $groups): Responsible for saving the field's content to your storage mechanism.
Resolvers are typically placed in app/Nova/Flexible/Resolvers.
use Whitecube\NovaFlexibleContent\Value\ResolverInterface;
use Whitecube\NovaFlexibleContent\Layouts\Collection;
class WysiwygPageResolver implements ResolverInterface
{
public function get($resource, $attribute, $layouts)
{
// Logic to retrieve data and return hydrated layouts
}
public function set($model, $attribute, $groups)
{
// Logic to save the $groups to your database
}
}