Use guzzle!
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?
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();
Please or to participate in this conversation.