ORDERBY, ignore accents

2

I have a name column that belongs to the Producer_BVU model, whose names are:

2M1J
A. Coelho
ÓRBITA
Bruno

When I order:

\App\Producer_BVU::orderBy('name', 'ASC')->get();

The output is:

ÓRBITA
2M1J
A. Coelho
Bruno

Is there any way, preferably without modifying mysql's charset settings, in this query% with% accents being ignored?

Whose desired result is:

2M1J
A. Coelho
Bruno
ÓRBITA

It can be with some laravel function after extraction of the data without problem, it does not have to be soon in the call to the database, to cut until I prefer.

My settings in config / database for mysql:

...
    'mysql' => [
        'driver' => 'mysql',
        'host' => env('DB_HOST', '127.0.0.1'),
        'port' => env('DB_PORT', '3306'),
        'database' => env('DB_DATABASE', 'forge'),
        'username' => env('DB_USERNAME', 'forge'),
        'password' => env('DB_PASSWORD', ''),
        'unix_socket' => env('DB_SOCKET', ''),
        'charset' => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix' => '',
        'strict' => true,
        'engine' => null,
    ],
...
    
asked by anonymous 04.01.2018 / 10:50

1 answer

2

You do not need to specify ASC , because by default this is already the case. Just specify the DESC .

$collection = \App\Producer_BVU::orderBy('name')->get();

Alternative sorting function:

$collection = $collection->sortBy('name');

$collection->values()->all();

Another way is to change the settings of the driver mysql to database.php , which I consider to be more correct not to have to use unnecessary resources like the one above.

'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
    
04.01.2018 / 11:38