The question is straightforward. I don't prefer to write "controller code" in blade file. However, I can't convert title (user input) to formatted title directly because of locale language differences. I want to write switch case code in blade file like that:
switch ($word_char) {
case 'a':
case 'A':
$word_char_new = 'A';
break;
case 'b':
case 'B':
$word_char_new = 'B';
break;
case 'c':
case 'C':
$word_char_new = 'C';
break;
case 'ç':
...
Is this a good practice or should I avoid it?
It's a bad practice, you shouldn't do anything similar in a controller. The Laravel way is to create global helper in case if you'll use it a lot:
if (! function_exists('convertChars')) {
function convertChars()
{
$result = ....
....
return $result;
}
}
Add it to a custom helpers.php
and autoload it by putting this into composer.json
which is in Laravel root directory:
"autoload": {
....
"files": [
"app/someHelpersDirectory/helpers.php"
]
},
Also, since you're trying to convert non-latin characters to latin ones, I guess this method from my package will help you to create more concise and readable helper.