Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save toonvandenbos/c04b85435a5cb92ac4e09ab506537962 to your computer and use it in GitHub Desktop.
Save toonvandenbos/c04b85435a5cb92ac4e09ab506537962 to your computer and use it in GitHub Desktop.
Examples used in Medium Post "Making Laravel Nova custom fields more developer-friendly"
<?php
use Acme\MyNovaField\MySerializableNovaFieldValue;
// ...
protected function fillAttributeFromRequest(NovaRequest $request, $requestAttribute, $model, $attribute)
{
if (!$request->exists($requestAttribute)) return;
// Let's handle and wrap the request's value into our own Value Object
$value = new MySerializableNovaFieldValue($request[$requestAttribute]);
// And assign this serializable wrapper directly to the model's attribute
$model->{$attribute} = $value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment