Last active
March 26, 2019 12:20
-
-
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"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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