Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using custom slug_normalizer #182

Open
iRajul opened this issue Apr 11, 2024 · 0 comments
Open

using custom slug_normalizer #182

iRajul opened this issue Apr 11, 2024 · 0 comments

Comments

@iRajul
Copy link

iRajul commented Apr 11, 2024

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 spatie/laravel-markdown#33 (reply in thread)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant