1

I recently upgraded Laravel version in the project to 6.x.

Now I know the helpers class have been removed from Laravel 6.0 version.

But anyway I need to keep the [root-dir]/helpers.php file which is functions oriented, non-class file containing general purpose helper functions.

In that file I need to replace all the custom functions starting with str_ like str_contains with Illumimnate\Support\Str counterparts like Str::contains. For example:

if(!function_exists('is_bot'))
{
    /**
     * userAgent is the user-agent header
     * from the request object
     * @param $userAgent
     * @return bool
     */
    function is_bot($userAgent)
    {
        return str_contains($userAgent, config('bot_check'));
    }
}

How can I do that ?

Vicky Dev
  • 1,893
  • 2
  • 27
  • 62

2 Answers2

2

You can only use namespace and use within class files. You could transform your helpers.php file into a class like this:

<?php

namespace App;

use Illuminate\Support\Str;

class Helper
{
    public static function is_bot($userAgent)
    {
        return Str::contains($userAgent, config('bot_check'));
    }
}

And call is_bot function inside your Laravel application with \App\Helper::is_bot($userAgent).

guizo
  • 2,594
  • 19
  • 26
0

The helpers removed due to a guy being complaining about them however they moved it to a new package https://github.com/laravel/helpers

Link to laravel's pull request https://github.com/laravel/framework/pull/26898

AH.Pooladvand
  • 1,944
  • 2
  • 12
  • 26