Level 2
Try including Inertia before class .
use Inertia\Inertia;
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi Everyone, I am having an issue using Inertia::share in AppServiceProvider. The following code produces this error:
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
public function register() {
Inertia::share(function () {
return ['app' => ['sitename' => config('app.name')]];
});
}
public function boot() {
Inertia::share([
'locale' => function () {
return app()->getLocale();
},
'language' => function () {
return translations(
resource_path('lang/'. app()->getLocale() .'.json')
);
},
]);
}
}
Error in artisan below:
Class 'App\Providers\Inertia' not found
at app/Providers/AppServiceProvider.php:15
11▕ *
12▕ * @return void
13▕ */
14▕ public function register() {
➜ 15▕ Inertia::share(function () {
16▕ return ['app' => ['sitename' => config('app.name')]];
17▕ });
18▕ }
19▕ /**
+7 vendor frames
8 artisan:37
Illuminate\Foundation\Console\Kernel::handle()
If I remove the Inertia::share calls, then there are no errors in artisan. Any ideas why this could cause this error?
@Akash_kushwaha wow, thank you :D. Can't believe it is that simple !
Please or to participate in this conversation.