Laravel-Markdown
Laravel-Markdown copied to clipboard
using custom slug_normalizer
If someone wants to add custom slug_normalizer
Example :
class CustomMarkdownNormalizer implements TextNormalizerInterface
{
use Resumeable;
public function normalize(string $text, $context = null): string
{
// Use Laravel's Str::slug function
return Str::slug($text);
}
}
As closure in config file give error during php artisan config:cache
So use following trait to use with custom class:
<?php
trait Resumeable
{
public static function __set_state(array $state_array): static
{
$object = new static();
foreach ($state_array as $prop => $state) {
if (!property_exists($object, $prop)) continue;
$object->{$prop} = $state;
}
return $object;
}
}
Source https://github.com/spatie/laravel-markdown/discussions/33#discussioncomment-5749252