laravel 5.5返回重定向路由不工作

时间:2018-01-10 08:59:09

标签: php laravel

我的laravel应用程序出现了一个奇怪的问题。

我的路线定义为:

web.php

Route::get('/', ['as' => '/', 'uses' => 'LoginsController@getLogin']);
Route::post('/login', ['as' => 'login', 'uses' => 'LoginsController@postLogin']);

Route::group(['middleware' => ['authenticate', 'roles']], function (){
    Route::get('/logout', ['as' => 'logout', 'uses' => 'LoginsController@getLogout']);
    Route::get('/dashboard','DashboardController@dashboard')->name('dashboard');
});

在控制器中,我试图重定向到此路线

LoginController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class LoginsController extends Controller
{
    use AuthenticatesUsers;

    protected $username = 'username';
    protected $redirectTo = '/';
    protected $guard = 'web';

    public function getLogin()
    {
        if (Auth::guard('web'))
        {
            return redirect()->route('dashboard');
        }
        return view('login');
    }

    public function postLogin(Request $request)
    {
        $auth = Auth::guard('web')->attempt([
            'username' => $request->username,
            'password' => $request->password,
            'active' => 1]);
        if ($auth)
        {
            return redirect()->route('dashboard');
        }
        return redirect()->route('/');
    }

    public function getLogout()
    {
        Auth::guard('web')->logout();
        return redirect()->route('/');
    }
}

我在浏览器的地址栏中输入http://localhost:8000的位置。我明白了。

When I am it runnig

0 个答案:

没有答案