Laravel路由重定向问题

时间:2017-06-13 13:40:36

标签: php laravel controller routes laravel-5.4

我在将管理页面重定向到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');
});

enter image description here

1 个答案:

答案 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'));

   } 

希望这对你有用!