Support the ongoing development of Laravel.io →
posted 10 years ago
Requests

I can't seem to work out how I would redirect user to new post by using the slug instead of ID. the documentation talks about retrieving the id and redirecting to that when successfully submitting a form.

I am not using ID to show posts i am using a slug

/posts/post-name-slug instead of /posts/id

I am using RESTful controllers so in this case the id/slug is passed to the show method.

Any ideas? :) thanks

Last updated 2 years ago.
0
Route::model('blog', 'Blog');

Route::bind('blog', function($value, $route) {
    return Blog::whereUrl($value)->first();
});

Assuming you have a Blog model the above code should do the trick.

Blog:whereUrl is simply doing a search on a column name of your choice.

You bind a parameter to a model and then in your binding you specify what column value you want to use as a parameter

Last updated 10 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

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.

© 2025 Laravel.io - All rights reserved.