dimanche 4 août 2019

Slug is not passing 'question mark'

I am creating slug from title in a Laravel based website. When I am creating, fetching slug everything is working fine. But when I am trying to see the details of the post, I am passing slug in the route. But the slug is missing its question mark.

I am using the following code to make the slug:

public function make_slug($string) { return preg_replace('/\s+/u', '-', trim($string)); }

I am using this code because that site is used for other language than english. This code makes the slug just fine. For example:

My post title is: What is Lorem Ipsum?

My slug will be: what-is-lorem-ipsum?

I am saving and fetching this slug just fine.

My details route looks like: https://example-v2.dev/post/what-is-lorem-ipsum?

This route is even shown in my browser URL. But when I am getting it in my controller the slug becomes like the following:

what-is-lorem-ipsum

The question mark is removed. Which results in an error as I am querying database using slug. What is the problem here? Also what is the fix?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire