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
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
}
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community