我在将管理页面重定向到Route :: resource()时遇到问题;这样我就可以从BookController
显示我的CRUD了我做错了什么?
这是我的AdminLoginController:
public function __construct(){
$this->middleware('guest:admin');
}
public function showLoginForm(){
return view('auth.admin-login');
}
public function login(Request $request){
$this->validate($request, [
'email' => 'required|email',
'password' => 'required|min:6'
]);
if(Auth::guard('admin')->attempt(['email' => $request->email, 'password' => $request->password],$request->remember)){
return redirect()->intended(route('books.index'));
}
return redirect()->back()->withInput($request->only('email','remember'));
}
BookController的
public function index()
{
$books = Book::orderBy('id','desc')->paginate(3);
return view('books.index')->withBooks($books);
}
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('/books/','BookController@index');
});
答案 0 :(得分:0)
我认为您应该更新books
路线:
Route::get('/books/','BookController@index')->name('books.index');
或强>
Route::group(['prefix' => 'admin'], function () {
Route::resource('/books','BookController@index');
});
并检查route
php artisan route:list
名称
更新您的代码,如:
if(Auth::guard('admin')->attempt(['email' => $request->email, 'password' => $request->password],$request->remember)){
return redirect()->intended(route('admin.books.index'));
}
希望这对你有用!