Support the ongoing development of Laravel.io →
Requests Queues Architecture
Last updated 2 years ago.
0

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 2 years ago.
0

This is a nice packet for laravel to handle that automatically: https://github.com/cviebrock/eloquent-sluggable

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 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Zolax zolax Joined 21 Jul 2014

Moderators

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

Your logo here?

Laravel.io

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

© 2024 Laravel.io - All rights reserved.