Support the ongoing development of →
Requests Queues Architecture
Last updated 1 year ago.

Update posts table to include slug row and look at Laravel's Str class, Str::slug in particular.

So just save the post's title using Str::slug($title, '-') and use the slug to display proper link

Last updated 1 year ago.

This is a nice packet for laravel to handle that automatically:

You just add this to your model:

    use SluggableTrait;

    protected $sluggable = array(
        'build_from' => 'title',
        'save_to'    => 'slug',

And when you first save the model title, for example "Hello World!", it will add a unique slug like "hello-world" in the slug-field in the database. Then you can just do something like this in the controller:

public function somePageController( $slug ) {
    $post = Post::whereSlug($slug)->get();
    // .. display page
Last updated 1 year ago.

Sign in to participate in this thread!


Your banner here too?

Zolax zolax Joined 21 Jul 2014


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 - All rights reserved.