Single Post and SEO Friendly URL – WordPress-Like Blog Laravel 5.7 and AdminLTE 3 (5)

WordPress-Like Blog Laravel 5.7 and AdminLTE 3 (5) – Single Post and SEO Friendly URL

In this fifth part of creating WordPress-Like Blog using Laravel 5.6/5.7 and AdminLTE 3, we will :

  1. Create the single post
  2. Create SEO Friendly URL

In the previous part, we have successfully created a page shows all the post from the posts table. Now we will create a single page to show the single post. First, let’s modify routes/web.php

Next, open BlogController.php and create new method show() :

Open resources/views/blog/index.blade.php and modify the href part for the post title :

Open resources/views/layouts/main.blade.php and add styling to the header. This styling is added to make the post title color stays black and no underline :

Open resources/views/blog/show.blade.php and do some modifications. The end result will be as follows :

Open terminal and php artisan serve. Open your laravel blog project, and click the title.

Membuat Blog dengan Laravel 5.6 dan AdminLTE 3 (5) – Single Post dan URL SEO Friendly

SEO Friendly URL

Before we start changing the url to be more SEO friendly, let’s change the method show() in the BlogController using model binding :

Next, we will start to use the SEO friendly url.

Open app\Providers\RouteServiceProvider.php and modify the boot method :

The ‘posts’ inside the bind method should be the same with the {posts} we use in the routes/web.php. Published() is used to prevent visitor to open unpublished posts.

Don’t forget to use App\Post in RouteServiceProvider.php

Next, modify the blog/index.blade.php and change $post->id to $post->slug.

Head over to your home url, and click one of the title :

Membuat Blog dengan Laravel 5.6 dan AdminLTE 3 (5) – Single Post dan URL SEO Friendly 2

Github Commit.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.