VinoCoder
VinoCoder

Reputation: 1153

Construct function not working in Laravel helper

I'm using Laravel version 6.x. I have created one helper function called GraphqlApi.

My helper class will look like below:

<?php

namespace App\Helpers;

/**
 * GraphqlApi class
 */
class GraphqlApi
{
     public function __construct() {
          echo "test";die;
     }
}

But whenever I call any function from helper class construct function is not being called.

Is there any way to make it work?

Upvotes: 0

Views: 581

Answers (1)

Andy Song
Andy Song

Reputation: 4684

if you always want the constructor to be called when you are calling other methods.

First, you can not have static method.

Second, call the method this way.

$graphqlApi = new GraphqlApi();

$result = $graphqlApi->getGuzzleRequest();

This way the constructor will be called.

Upvotes: 1

Related Questions