Laravel-Markdown icon indicating copy to clipboard operation
Laravel-Markdown copied to clipboard

using custom slug_normalizer

Open iRajul opened this issue 10 months ago • 0 comments

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

iRajul avatar Apr 11 '24 13:04 iRajul