PHP code example of laravel-pulse / sluggish

1. Go to this page and download the library: Download laravel-pulse/sluggish library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

laravel-pulse / sluggish example snippets

bash
php artisan vendor:publish --provider="LaravelPulse\Sluggish\SluggishServiceProvider"
bash
use LaravelPulse\Sluggish\Sluggish;

// create slug
public function store(Request $request)
{
    $post = Post::create([
        'title' => $request->title,
        'slug' => Sluggish::generate('slug', $request->title, Post::class, 'slug') // hello-world , hello-world-1, hello-world-2 .....
    ]);

    return redirect()->route('posts.index');
}

// update slug
public function update(Request $request,Post $post)
{
    $post->update([
        'title' => $request->title,
        'slug' => Sluggish::generate("slug", $request->title, Post::class, 'slug', $post)
        // if it get same id and same title  return existing slug
        // otherwise
        // hello-world , hello-world-1, hello-world-2 .....
    ]);

    return redirect()->route('posts.index');
}