Laravel重定向到正确的页面但显示错误的URL

时间:2016-12-23 13:47:57

标签: php html laravel laravel-5 laravel-5.3

单击登录按钮后,主页面会打开,这是正确的,但在URL中显示/ handleLogin而不是/ home

此外,当我退出时,登录页面重新打开,这是正确的,但在URL中,当登录页面实际打开时,它会显示/注销。 为什么会这样?

LoginController.php     

from_json

routes.php文件

namespace App\Http\Controllers;


use Illuminate\Http\Request;
use Illuminate\Http\RedirectResponse;

use App\User;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class LoginController extends Controller
{
/*
|----------------------------------------------------------------------      ----
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
| 
*/

/* Login function*/
public function login(){
    return view('login');
}

/* handleLogin function to request the data*/
public function handleLogin(Request $request){
    $data = $request-> only('email', 'password');
    if(\Auth::attempt($data)){
    return redirect()-> intended('home');
    }

return back()->withInput();
}


public function logout(){
    \Auth::logout();
    return redirect()->route('login');
}


}

master.blade.php     

<?php

            /*
            |--------------------------------------------------------------------------
            | Web Routes
            |--------------------------------------------------------------------------
            |
            | Here is where you can register web routes for your application. These
            | routes are loaded by the RouteServiceProvider within a group which
            | contains the "web" middleware group. Now create something great!
            |
            */

            Route::get('/', function() {
                return view('welcome');
                //return 'Hello. This is Laravel.';

            });

            Route::get('aboutus', function() {
                return view('AboutUs');
                //return 'Hello. This is Laravel.';
            });

            //Route::group(['middleware' => ['web']], function() {

                Route::get('/login', ['as' => 'login', 'uses' => 'LoginController@login']);
                Route::post('/handleLogin', ['as' => 'handleLogin', 'uses' => 'LoginController@handleLogin']);
                Route::get('/home', ['as' => 'home', 'uses' => 'UsersController@home']);
                Route::get('/logout', ['as' => 'logout', 'uses' => 'LoginController@logout']);
            //});

表格刀片。

        <div data-role="navbar">

        <ul>
            @if(\Auth::check())
            <li>
                {{ link_to_route('logout', "Logout")}}
            </li>
            @else
            <li>
                {{ link_to_route('login', "Login")}}
            </li>
            @endif
        </ul>


        </div>

0 个答案:

没有答案