Support the ongoing development of Laravel.io →
Configuration Requests Input
Last updated 1 year ago.
0

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);
    }
}
Last updated 1 year ago.
0

But shouldnt the slug replace the id parameter fx.?

Or will that happen automatically?

Last updated 1 year ago.
0

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.

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Reached reached Joined 27 Feb 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.