-
Notifications
You must be signed in to change notification settings - Fork 35
Closed
Labels
bugVerified bug by the Nova teamVerified bug by the Nova team
Description
- Laravel Version: 9.31.0
- Nova Version: 4.15.1
- PHP Version: 8.1
- Database Driver & Version: MySQL 8
- Operating System and Version: Ubuntu 22.04
- Browser type and version: Chrome, latest
- Reproduction Repository: None
Description:
By clicking "Preview" on Markdown field (currently using default driver) when the field is empty, I receive an error stating that the value is expected to be string rather than null:

As the error states, the issue happens in Laravel\Nova\Fields\Markdown\DefaultPreset:15
<?php
namespace Laravel\Nova\Fields\Markdown;
use Illuminate\Support\Str;
class DefaultPreset implements MarkdownPreset
{
/**
* Convert the given content from markdown to HTML.
*
* @param string $content
* @return string
*/
public function convert(string $content) // if we change it to ?string it would just break later on
{
return Str::markdown($content);
}
}Obviously enough, this issue is shared among all the drivers, hence the optimal fix should be placed in Laravel\Nova\Fields\Markdown:105
/**
* Return a preview for the given field value.
*
* @param string $value
* @return string
*/
public function previewFor($value)
{
// could add __( ) for allowing translations, default it to empty string or expose a method to set the default value
return $this->renderer()->convert($value ?? 'Nothing to preview');
}Detailed steps to reproduce the issue on a fresh Nova installation:
- Add a Markdown field inside any resource
- No specific driver is required
- Go to edit view and try to Preview the markdown while it is empty
Metadata
Metadata
Assignees
Labels
bugVerified bug by the Nova teamVerified bug by the Nova team