<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>unique slug Archives - Codeplaners</title>
	<atom:link href="https://codeplaners.com/tag/unique-slug/feed/" rel="self" type="application/rss+xml" />
	<link>https://codeplaners.com/tag/unique-slug/</link>
	<description>Code Solution</description>
	<lastBuildDate>Sat, 30 Oct 2021 08:13:05 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.1.7</generator>

<image>
	<url>https://codeplaners.com/wp-content/uploads/2020/09/cropped-favicon-social-32x32.png</url>
	<title>unique slug Archives - Codeplaners</title>
	<link>https://codeplaners.com/tag/unique-slug/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Laravel 8 Create Unique Slug Example</title>
		<link>https://codeplaners.com/laravel-8-create-unique-slug-example/</link>
					<comments>https://codeplaners.com/laravel-8-create-unique-slug-example/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sat, 30 Oct 2021 08:13:05 +0000</pubDate>
				<category><![CDATA[Laravel]]></category>
		<category><![CDATA[Laravel 8]]></category>
		<category><![CDATA[Source Code]]></category>
		<category><![CDATA[unique slug]]></category>
		<guid isPermaLink="false">https://codeplaners.com/?p=1350</guid>

					<description><![CDATA[<p>Hi Dev, Today, i we will show you laravel 8 create unique slug example. This article will give you simple example of laravel 8 create unique slug example. you will laravel 8 create unique slug example. In this article, we will implement a laravel 8 create unique slug example. So let’s follow few step to &#8230; <a href="https://codeplaners.com/laravel-8-create-unique-slug-example/" class="more-link">Continue reading<span class="screen-reader-text"> "Laravel 8 Create Unique Slug Example"</span></a></p>
<p>The post <a rel="nofollow" href="https://codeplaners.com/laravel-8-create-unique-slug-example/">Laravel 8 Create Unique Slug Example</a> appeared first on <a rel="nofollow" href="https://codeplaners.com">Codeplaners</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Hi Dev,</p>
<p>Today, i we will show you laravel 8 create unique slug example. This article will give you simple example of laravel 8 create unique slug example. you will laravel 8 create unique slug example. In this article, we will implement a laravel 8 create unique slug example. </p>
<p>So let’s follow few step to create example of laravel 8 create unique slug example.</p>
<h3 class="step_code">Slug Example</h3>
<p><strong>app/Models/Pages.php</strong></p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;

class Pages extends Model
{

	/**
	 * The attributes that are mass assignable.
	 *
	 * @var array
	 */
	protected $fillable = &#x5B;
		'title', 'contant', 'slug'
	];


    protected static function boot()
    {
        parent::boot();
        static::created(function ($post) {
            $post-&gt;slug = $post-&gt;createSlug($post-&gt;title);
            $post-&gt;save();
        });
    }

    private function createSlug($title){
        if (static::whereSlug($slug = Str::slug($title))-&gt;exists()) {
            $max = static::whereTitle($title)-&gt;latest('id')-&gt;skip(1)-&gt;value('slug');
            if (is_numeric($max&#x5B;-1])) {
                return preg_replace_callback('/(\d+)$/', function ($mathces) {
                    return $mathces&#x5B;1] + 1;
                }, $max);
            }
            return &quot;{$slug}-2&quot;;
        }
        return $slug;
    }
}

</pre>
<p><strong>Controller Code:</strong></p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
  
namespace App\Http\Controllers;
  
use App\Models\Pages;
use Illuminate\Http\Request;
  
class PageController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $page = Pages::create(&#x5B;
            &quot;title&quot; =&gt; &quot;Laravel CRUD&quot;
        ]);
        dd($page);
    }
}
</pre>
<p><strong>Output:</strong></p>
<pre class="brush: php; title: ; notranslate">
Laravel-CRUD
Laravel-CRUD-2
Laravel-CRUD-3
</pre>
<p>I hope it will assist you…</p>
<p>The post <a rel="nofollow" href="https://codeplaners.com/laravel-8-create-unique-slug-example/">Laravel 8 Create Unique Slug Example</a> appeared first on <a rel="nofollow" href="https://codeplaners.com">Codeplaners</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://codeplaners.com/laravel-8-create-unique-slug-example/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
