'Class not found in call back function Laravel
Hitting an error in Laravel ServiceProvider, class not found even though it exists, and it throws an error inside the call back function, (not before) and btw it works fine locally but I got this error when deploying to GCP, might be a difference in php version or something? however what could a solution be here ? my code:
<?php
namespace App\Services\Tableau;
use Illuminate\Support\ServiceProvider;
use App\Services\Tableau\TableauClient;
class TableauServiceProvider extends ServiceProvider
{
public function register()
{
$this->app->bind(
TableauClient::class,
function () {
return new TableauClient(
config('services.tableau.server_url'),
);
}
);
}
}
it throws error on this line
return new TableauClient(
config('services.tableau.server_url'),
);
"Class 'App\Services\Tableau\TableauClient' not found"
what am I missing here ?
Solution 1:[1]
Register the Service Provider by adding the TableauServiceProvider class to config/app.php. Preferably, under Application Service Providers;
/*
* Application Service Providers...
*/
App\Providers\AppServiceProvider::class,
App\Providers\AuthServiceProvider::class,
// App\Providers\BroadcastServiceProvider::class,
App\Providers\EventServiceProvider::class,
App\Providers\RouteServiceProvider::class,
// Add your service provider here...
Also, check the namespace for Provider class. By convention, all providers live in the App\Providers namespace.
However, if you want to stick to the setup you have which I wouldn't recommend, then you can register your TableauServiceProvider like below:
App\Services\Tableau\TableauServiceProvider::class
as described above.
Hope this helps you out.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | petersowah |
