Laravel 5.5有问题。简单的网站工作正常。但是当我访问管理面板时,登录后出现此错误。
抛出ReflectionException并显示消息“类管理员不存在”
应用\ HTTP \中间件\ admin.php的
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Auth;
class Admin
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if(Auth::check() && Auth::user()->isAdmin()){
return $next($request);
}
return redirect('home');
}
}
web.php
Auth::routes();
Route::group(['prefix'=>'admin','middleware'=>['auth','admin']], function(){
Route::post('toggledeliver/{orderId}','OrderController@toggledeliver')->name('toggle.deliver');
Route::post('toggledeliver/{productId}','ProductsController@toggledeliver')->name('product.deliver');
Route::get('/',function(){
return view('admin.index');
})->name('admin.index');
});
答案 0 :(得分:6)
创建中间件后,您需要在app/http/Kernel.php
数组中的protected $routeMiddleware
文件中注册!然后,您可以在路线中使用此中间件( web.php / api.php )
像这样:
protected $routeMiddleware = [
'admin' => 'App\Http\Middleware\Admin',
];
希望这能帮到你!