Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

thomthom's avatar

How to structure a helper

In my Laravel app I need to interact with an external REST API.

I'm using CURL commands to interact with the API. (Please let me know if there are better alternatives.)

I want to create a helper class that takes care of this interaction, though, I'm very green to Laravel and this type of framework. Where do you usually put this - and would it be a plain class or would it build upon something in the framework?

0 likes
3 replies
mikebarwick's avatar
Level 5

Guzzle is included in Laravel by default.

Just create a "Helpers" folder in App (i.e. App/Helpers). Create a class and namespace it.

<?php

namespace App\Helpers;

class DoSomethingHelper
{

    /**
     * Do something method
     *
     * @return Response
     */
    public static function doSomething()
    {
        return 'something was done';
    }

}

Then in your controller or whatever, you could specify the helper and then use it...might not want to go the static function route though, but for this example, it's easier.

use App\Helpers\DoSomethingHelper;

echo DoSomethingHelper::doSomething();
1 like

Please or to participate in this conversation.