vendredi 23 décembre 2016

Laravel redirects to correct page but displays wrong 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>
                
            </li>
            @else
            <li>
                
            </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() !!}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire