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