我正在为我的laravel项目创建一个Admin后端。它正在使用laravel Auth脚手架。我在周末之后回到它后现在收到此错误,我正在努力寻找错误。我检查了所有拼写和大小写。我已经运行了作曲家更新等,但仍然没有运气。这是下面的错误,我确实有namespace App
中的管理类和它,不知道发生了什么:
ReflectionException error class admin does not exist.
Web.php文件
Route::prefix('admin')->group(function() {
Route::get('/login', 'Auth\AdminLoginController@showLoginForm')->name('admin.login');
Route::post('/login', 'Auth\AdminLoginController@login')->name('admin.login.submit');
Route::get('/', 'AdminController@index')->name('admin.dashboard');
Route::get('/logout', 'Auth\AdminLoginController@logout')->name('admin.logout');
});
AdminLoginController.php
<?php
namespace App\Http\Controllers\Auth;
use Auth;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
class AdminLoginController extends Controller
{
public function __construct()
{
$this->middleware('admin')->except('logout');
}
public function showLoginForm()
{
return view('auth.admin-login');
}
public function login(Request $request)
{
//Validate the form data
$this->validate($request, [
'email' => 'required|email',
'password' => 'required|min:6'
]);
// Attempt to log the user in
if (Auth::guard('admin')->attempt(['email' => $request->email, 'password' => $request->password], $request->remember)) {
// If successful, then redirect to tehir inteded page
return redirect()->intended(route('admin.dashboard'));
}
// unsuccessful, then redirect back to the login with the form data
return redirect()->back()->withInput($request->only('email', 'remember'));
}
public function logout()
{
Auth::guard('admin')->logout();
return redirect('/');
}
}
AdminController.php
<?php
namespace App\Http\Controllers;
use Auth;
use Illuminate\Http\Request;
class AdminController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth:admin');
}
/**
* Show the application dashboard.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
return view('admin');
}
}
答案 0 :(得分:0)
好的,所以我修好了!!在AdminLoginController中,我将此'guest:admin'
添加到此中间,而不仅仅是'admin'
中间件括号:
public function __construct()
{
$this->middleware('guest:admin')->except('logout');
}