moshemo
2 weeks ago

Path Function for URL With ID and Slug

Posted 2 weeks ago by moshemo

I am referencing this episode: https://laracasts.com/series/laravel-6-from-scratch/episodes/28?autoplay=true

In that episode, Jeffrey creates the following function in the Article model:

  public function path() {
    return route('article.show', $this);
  }

Now, this works just fine and returns the following url structure: www.mydomain.com/article/{id}

However, I would like to tweak it a bit. I want my url structure to be like this: www.mydomain.com/article/{id}/{slug}

So, what I want to know is how do I have to modify the path function in order to return this url structure - i.e., the one with both the id and the slug?

Please sign in or create an account to participate in this conversation.