0

I have a problem with my helper function called swe_date. It outputs nothing. If I don`t use it, all is good.

I have done the composer dump-autoload thing and put "app/helpers.php" in the composer.json file.

My helper function looks like this.

 if (! function_exists('swe_date'))
 {
  function swe_date($date)
  {
    setlocale(LC_TIME, 'sv_SV');
    return strftime('%A %d %B %Y %H:%M',strtotime($date));
  }
 }

My controller where I try to send my variable with my helper function. Notice when I do a dd(swe_date($suspended->suspended_until)) I got: b"söndag 22 september 2019 00:00" Don't know where the "b" comes from.

  $date = swe_date($suspended->suspended_until);
  //dd(swe_date($suspended->suspended_until));
  return redirect('/login')->with('date',$date);

The view where I try to show the message.

 @if(Session('date'))
    <div class="bg-danger mb-2 text-center text-white">
       {{Session('date')}}
    </div>
 @endif

composer.json

    "autoload": {
    "psr-4": {
        "App\\": "app/"
    },
    "classmap": [
        "database/seeds",
        "database/factories"
    ],
    "files": [
      "app/helpers.php"
      ]
},
Blue
  • 33
  • 5
  • Can you post your composer.json file? – Elad Aug 25 '19 at 11:45
  • using the set_locale require configuration on the machine where the code is running, for the specific locale to be available (have a look at "locale-gen" ) Also I think this is not working on windows but I 'm not sure about that one – jeremy_nikolic Aug 26 '19 at 02:39

1 Answers1

0

From php.net:

The "locale" always depend on the server configuration

The locale string need to be supported by the server.

Sometimes there are diferents charsets for a language, like "pt_BR.utf-8"

so if your server is windows try:

setlocale(LC_ALL, 'sv-SE.utf-8');

on linux try:

setlocale(LC_ALL, 'sv_SE.utf-8');

I think the UTF-8 will solve your "b" issue.

Also on linux make sure your language is supported "sudo locale -a"

if not follow this to install

Elad
  • 891
  • 5
  • 15