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

I would recommend not doing this at all !! It doesn't look really user friendly in the URL in most browser.

I assume you are using the name of the category in the URL to retrieve it from the database by that name, is that correct?

Well if that's so, i would create another column in your database, which will hold the URL slug ( category name written in non-utf8 characters ) of your category in it, like so:

--- TABLE categories ---
ID | 1
name | Gartenmöbel
slug | Gartenmobel

And yes this won't hurt your SEO, but will only help it. Google doesn't make a diffrence between an "e" and an "ë"

Your URL will look like this:

http://pergolaexpress.debian/category/Gartenmobel

I Would create a model for you categories table like this:

class Category extends Eloquent{

	protected $table = 'categories';
 	protected $primaryKey = 'id';


 	public function scopeGetBySlug($query, $slug){
 		return $query->where('slug', '=', $slug)->first();
 	}
}

Then finally in your code retrieve the category like:

$category = Category::getBySlug('Gartenmobel');

If you want to automaticlly create slugs form your category names, i would recommend the package Slugify. It has support for Russian, Chinese and German characters and lots more. I have a good experience with it!

You can get it here: https://packagist.org/packages/cocur/slugify

Last updated 1 year ago.
0

ok thanks, had a feeling that was going to be the answer :) And quite agree with what you say, due to the fact there is only one "troublemaker", i'll hack it. But thanks

Last updated 1 year ago.
0

Hi guys

actually i disagree with ssshenkie in his point of set the slug = Gartenmobel instead of Gartenmöbel.

browsers Have to accept all utf8 characters and i think most new browsers accepted that.

i use chrome and safari browsers and all these are showing words clearly.

Last updated 1 year ago.
0

I suggest you remove first() from your scope and add it to the call

$category = Category::getBySlug('Gartenmobel')->first();

Limiting yourself by placing the first() in the scope can become tricky really fast.

You can have multiple categories with the same slug but in different levels of the category tree.

Example

$category = Category::getBySlug('Gartenmobel')->where('parent', '=', 1)->first();
Last updated 1 year ago.
0

in the browser url field, it "looked" fine, that was my initial point, it looked fine but was landing over the route into my controller as "Gartenmöbel" - where obviously the encoding has become mangled

When i use "Gartenmöbel" in the controller, when written correctly it works, thats why i've ignored the slug suggestion. In this case its unecessary, i was mere curious where/why the encoding is getting lost/mangeled on its way into the controller.

Last updated 1 year ago.
0

recently, i have same problem, i just create next Middleware

<?php namespace App\Http\Middleware; use Closure; class UrlName { public function handle($request, Closure $next) { $url = rawurldecode($request->server->get("REQUEST_URI")); $request->server->set('REQUEST_URI', $url); return $next($request); } }
0

Sign in to participate in this thread!

Eventy

Your banner here too?

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.