Error in initializing index

While i am initializing client in laravel

$client = Algolia\AlgoliaSearch\SearchClient::create(
‘YourApplicationID’,
‘YourAdminAPIKey’
);

$index = $client->initIndex(‘your_index_name’);

It says:
Class ‘App\Http\Livewire\Algolia\AlgoliaSearch\SearchClient’ not found
Any solution for this

Hey @aditkhadka7 ,

Due to how PHP searches for classes in namespaces, you have to replace Algolia\AlgoliaSearch\SearchClient with \Algolia\AlgoliaSearch\SearchClient (note the \ at the beginning). Without the \ in front, PHP will try to resolve the namespace relative to the namespace you’re currently in (App\Http\Livewire). Adding the \ tells PHP to look from the ‘root’ namespace.

Replacing your code with the following will make it behave as expected:

$client = \Algolia\AlgoliaSearch\SearchClient::create(
'YourApplicationID',
'YourAdminAPIKey'
);

$index = $client->initIndex('your_index_name');

You can read more about PHP namespace lookups in the PHP documentation.

Cheers!