title: Laravel custom strings helper file
body: <p>I created an Artisan command file which handles strings in different encodings.</p>
  
  <p>I needed to implement a <code>mb_str_pad</code> function (and found <a href="https://gist.github.com/nebiros/226350" rel="nofollow noreferrer">this one</a>).</p>
  
  <p>I created a helper file <code>app/Library/Helpers/StringHelper.php</code>:</p>
  
  <pre><code>&lt;?php
  
  if (!function_exists('mb_str_pad')) {
      function mb_str_pad() {
          :
          :
      }
  }
  </code></pre>
  
  <p>Then I added it to <code>composer.json</code> file:</p>
  
  <pre><code>"autoload": {
      "classmap": [
          "database/seeds",
          "database/factories"
      ],
      "psr-4": {
          "App\\": "app/"
      },
      "files": [
          "app/Library/Helpers/StringHelper.php" // &lt;-- Here
      ]
  },
  </code></pre>
  
  <p>And run <code>composer dump-autoload</code>.</p>
  
  <p><strong>When I try to run the command (<code>php artisan mytasks:generate</code>) I get this error:</strong></p>
  
  <pre><code>Call to undefined function App\Console\Commands\mb_str_pad()
  </code></pre>
  
  <p><strong>2nd try:</strong><br>
  I also tried to add a service with:</p>
  
  <pre><code>php artisan make:provider StringHelperServiceProvider
  </code></pre>
  
  <p>In the <code>register()</code> function I put:</p>
  
  <pre><code>require_once app_path('Library/Helpers/StringHelper.php');
  </code></pre>
  
  <p>And in <code>app.php</code> added to <code>providers</code> array:</p>
  
  <pre><code>App\Providers\StringHelperServiceProvider::class,
  </code></pre>
  
  <p>But I get the same error.</p>
  
  <p>=========================== Edit ======================</p>
  
  <p>I have no good explanation for it, but now the same code works fine.</p>
  
  <p>The only thing I did was to test my function with Tinker:</p>
  
  <pre><code>$ php artisan tinker
  Psy Shell v0.9.9 (PHP 7.2.4-1+ubuntu16.04.1+deb.sury.org+1 — cli) by Justin Hileman
  &gt;&gt;&gt; mb_str_pad("Hello", 10);
  =&gt; "Hello     "
  &gt;&gt;&gt; mb_str_pad("Hello", 10, ' ', STR_PAD_LEFT);
  =&gt; "     Hello"
  &gt;&gt;&gt; mb_str_pad("Helló", 10, ' ', STR_PAD_LEFT);
  =&gt; "     Helló"
  &gt;&gt;&gt; 
  </code></pre>
  
  <p><strong>I leave this question in case it will help somebody.</strong></p>