Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change Laravel 5.2 change login route?

Hello I am using Laravel 5.2 version. I installed the laravel project via composer. After that I use command "php artisan make:auth" for create auth. After created auth route is generated for example "http://localhost:8000/login". Now I don't want this route I want to set different route for example "http://localhost:8000/super/admin". So How can I change the "http://localhost:8000/login" to "http://localhost:8000/super/admin". And when auth generated that time /register route is create so that route i want to remove "http://localhost:8000/register" route. Please suggest me how to do this. Thanks in advance.

like image 925
sandip kakade Avatar asked Nov 26 '16 18:11

sandip kakade


People also ask

How do I change my auth login URL in laravel?

To change the login URL's you should look for the Route::auth() method inside your routes/web. php and remove it.

What is Auth :: Routes () in laravel?

Auth::routes() is just a helper class that helps you generate all the routes required for user authentication. You can browse the code here https://github.com/laravel/framework/blob/5.3/src/Illuminate/Routing/Router.php instead.


Video Answer


2 Answers

Follow these simple steps

If you have Route::auth() in your routes.php, then please remove that line.

Now add the following lines to your routes.php

Route::get('super/admin', 'Auth\AuthController@getLogin')->name('auth.login.get');
Route::post('super/admin', 'Auth\AuthController@postLogin')->name('auth.login.post');
Route::get('super/admin/logout', 'Auth\AuthController@getLogout')->name('auth.logout.get');

Then go to login.blade.php (most probably in resources->views->auth)

And change the form action to {{ route('auth.login.post') }}, like this...

<form action="{{ route('auth.login.post') }}" method="post">

Hope this answers everything :)

like image 103
prateekkathal Avatar answered Oct 06 '22 01:10

prateekkathal


In App\Http\Controllers\Auth\LoginController - define a fuction named showLoginForm() as:

public function showLoginForm()
{
    $view = property_exists($this, 'loginView')
        ? $this->loginView : 'auth.authenticate';

    if (view()->exists($view)) {
        return view($view);
    }
    return view('auth.login');
}

It overrides the function showLoginForm defined in the trait Illuminate\Foundation\Auth\AuthenticatesUsers.

Note: In Laravel 5.3 the function name is changed from getLogin to showLoginForm. For details goto Illuminate\Foundation\Auth\AuthenticatesUsers.

like image 23
Md. Abu Taleb Avatar answered Oct 06 '22 00:10

Md. Abu Taleb