duan20081202 2016-12-23 13:47
浏览 94

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

Upon clicking the login button, the home page opens, which is right but in the url it displays /handleLogin instead of /home

Also, when i log out, the login page reopens which is right but in the url it displays /logout when the login page is actually open. Why is this happening?

LoginController.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');
}


}

Routes.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']);
            //});

master.blade.php

        <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>

The form blade.

         {!! Form::open(array('route' => 'handleLogin')) !!}
    <div class="form-group">
        {!! Form::label('email') !!}
        {!! Form::text('email', null, array('class' => 'form-control')) !!}
    </div>
    <div class="form-group">
      {!! Form::label('password') !!}
      {!! Form::password('password', array('class' => 'form-control')) !!}
    </div>
    {!! Form::token() !!}
    {!! Form::submit('Login', array('class' => 'btn btn-default')) !!}
  {!! Form::close() !!}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
    • ¥20 怎么用dlib库的算法识别小麦病虫害
    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 java写代码遇到问题,求帮助
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?