In exactly the same way you have added previous url parameters, a slug is no different it's just another column in the table mapped to your model.
// routes.php
Route::get('/books/{slug}', [
'as' => 'read-book',
'uses' => 'BooksController@read'
]);
// BooksController.php
class BooksController extends Controller
{
public function read($slug)
{
$book = Book::whereSlug($slug)->first();
return View::make('books.read')->withBook($book);
}
}
But shouldnt the slug replace the id parameter fx.?
Or will that happen automatically?
It happens automatically if the slug exist.
Check out this tutorial I created on eloquent-sluggable: http://buildweek.com/clean-url-laravel/
Might be able to help you out.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community