我有一个自定义中间件,我想在其中使用单例功能,用于将php变量传递到前端,但是出现以下错误:
ReflectionException (-1)
Class App\Http\Middleware\Javascript does not exist
我的中间件:
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Auth;
class AuthAdmin
{
public function handle($request, Closure $next)
{
$user = Auth::user();
if($user && $user['privileges'] > 2)
{
return $next($request);
}
app(Javascript::class)->put(['showLoginModal' => true]);
return redirect('/');
}
}
我的服务提供商:
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use App\Helpers\Javascript;
class JavascriptServiceProvider extends ServiceProvider
{
public function register()
{
$this->app->singleton(Javascript::class, Javascript::class);
}
}
composer dump-autoload没有解决任何问题,由于某些原因,我一直遇到找不到Javascript类的问题,是否有任何想法或建议?
答案 0 :(得分:0)
尝试在中间件中导入Javascript类。试图在错误的命名空间中找到它。
中间件:
<?php
namespace App\Http\Middleware;
use App\Helpers\Javascript;