Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

lukegalea16's avatar

Changing URL Query shown

Hi, so first of all.

  1. Is it recommended to use Laravel as a website framework for blog posts etc.?
  2. To view blog posts the usual way is to fetch articles using query URLs such as domain.com/articles/{article-id} to fetch a particular article... However in most cases when I'm reading news etc I see the url as domain.com/articles/this-is-an-article-title... How can I achieve something similar please? Perhaps the id should be a string with the actual title?

Thanks

0 likes
5 replies
tykus's avatar

Is it recommended to use Laravel as a website framework for blog posts etc.?

No issue if you want to build all of the logic associated with drafting and publishing blog posts etc., but there are ready-made solutions for this already. As a learning exercise, it is a well-trodden path!

How can I achieve something similar please? Perhaps the id should be a string with the actual title?

You can use a slug of the post title as the identifier in the URL. Wherever you create a Post, you would dynamically determine the slug from its title (e.g. using Str::slug($post->title)) and persist that in a slug column on the posts table. If you use Laravel's Route Model binding, you can set to route key name to slug rather than the default id,

// app/Post.php

public function getRouteKeyName()
{
    return 'slug';
}

or if you prefer you can simply make the query yourself.

public function show($slug)
{
    $post = Post::where('slug', $slug)->firstOrFail();

    // return the view with the Post
}

You will need to ensure that a slug is unique for you application, so that the correct post is returned - there are packages that can help with this.

lukegalea16's avatar

Hi @tykus thank you for the valuable information. Which ready made solutions would you recommend please?

tykus's avatar

Wordpress 🤷‍♂️ Statimic

Cronix's avatar

There aren't really any "ready made solutions." Laravel is like lego blocks. It's up to you to put the pieces together however you need to build your final product. A ready made solution (non-Laravel) would be something like WordPress.

1 like

Please or to participate in this conversation.