Friday 4 October 2019

Add tinymce editor in html.


Add tinymce editor in html .

<script src="https://cloud.tinymce.com/stable/tinymce.min.js?apiKey=it4zoxdg71l304mwi6vi3bsu9i21oetwz5tf3r5tfldqecbk"></script>


Based on ID


        $("#txtEditor").Editor();
  tinymce.init({
    selector: '#shaons'
  });

Based on Class 

   tinymce.init({
    selector: '.standard-editor'
  });

create unique page url slug in laravel.

Create unique page url slug in laravel.    


public function createSlug($title, $id = 0)
    {
        // Normalize the title
        $slug = str_slug($title);

        // Get any that could possibly be related.
        // This cuts the queries down by doing it once.
        $allSlugs = $this->getRelatedSlugs($slug, $id);

        // If we haven't used it before then we are all good.
        if (! $allSlugs->contains('singleurl', $slug)){
            return $slug;
        }

        // Just append numbers like a savage until we find not used.
        for ($i = 1; $i <= 10; $i++) {
            $newSlug = $slug.'-'.$i;
            if (! $allSlugs->contains('singleurl', $newSlug)) {
                return $newSlug;
            }
        }

        throw new \Exception('Can not create a unique slug');
    }

    protected function getRelatedSlugs($slug, $id = 0)
    {
        return Blog::select('singleurl')->where('singleurl', 'like', $slug.'%')
            ->where('id', '<>', $id)
            ->get();
    }

$this->createSlug(request()->heading);