Example of Global helpers in akaunting/akaunting

File app/Utilities/helpers.php (link to Github)
// We just create a list of functions that don't belong to any class
// But, since they are global functions, it's important to check if their names don't exist somewhere else
// Notice: you can create this file in any folder you want. In this case, they created it in app/Utilities

if (!function_exists('user')) {
    function user()
    {
        if (request()->isApi()) {
            $user = app('Dingo\Api\Auth\Auth')->user();
        } else {
            $user = auth()->user();
        }

        return $user;
    }
}

if (!function_exists('company_date_format')) {
    function company_date_format()
    {
        $date_time = new class() {
            use DateTime;
        };

        return $date_time->getCompanyDateFormat();
    }
}

// ... other functions
File composer.json (link to Github)
// We autoload that helper file in our composer.json

{
    "name": "akaunting/akaunting",
    "description": "Free accounting software, based on Laravel framework.",
    // ... other values

    "autoload": {
        "files": [
            "app/Utilities/helpers.php"
        ]
    },

    // ... other values
}
File app/Http/Controllers/Auth/Login.php (link to Github)
// And we can use functions like user() in any class, like Controller
// In fact, user() function is used 11 times over whole project

class Login extends Controller
{
    public function store(Request $request)
    {
        // Get user object
        $user = user();

        // Check if user is enabled
        if (!$user->enabled) {
            $this->logout();

            return response()->json([
                'status' => null,
                'success' => false,
                'error' => true,
                'message' => trans('auth.disabled'),
                'data' => null,
                'redirect' => null,
            ]);
        }

        // ... other code of this method
    }
}

Additional resources on global helpers: