madala's avatar

route::has

@if (Route::has('login'))

            <div class="top-right links">

                <a href="{{ url('/login') }}">Login</a>

                <a href="{{ url('/register') }}">Register</a>

            </div>

        @endif 

can any one explain the Route::has what it does.

0 likes
10 replies
davielee's avatar

It just checks if the given route name is a registered route. For example...

Route::get('login', function() {
    // ...
})->name('login');

If that name() doesn't exist, then the has() call would return false. This would be more useful when you don't actually load all your routes with every request.

6 likes
madala's avatar

@craigpaul

Route::get('/', function () { return view('welcome'); });

Auth::routes();

Route::get('/home', 'HomeController@index');

i just install the laravel and run php artisan make:auth

davielee's avatar
davielee
Best Answer
Level 11

@madala by default, Auth::routes() registers a login route with the name login. Checkout the body of the method here.

public function auth()
{
    // Authentication Routes...
    $this->get('login', 'Auth\LoginController@showLoginForm')->name('login');
    $this->post('login', 'Auth\LoginController@login');
    $this->post('logout', 'Auth\LoginController@logout')->name('logout');

    // Registration Routes...
    $this->get('register', 'Auth\RegisterController@showRegistrationForm')->name('register');
    $this->post('register', 'Auth\RegisterController@register');

    // Password Reset Routes...
    $this->get('password/reset', 'Auth\ForgotPasswordController@showLinkRequestForm');
    $this->post('password/email', 'Auth\ForgotPasswordController@sendResetLinkEmail');
    $this->get('password/reset/{token}', 'Auth\ResetPasswordController@showResetForm');
    $this->post('password/reset', 'Auth\ResetPasswordController@reset');
}

That is why you are receiving true for that has() check.

5 likes
Amn's avatar

Its on github . Can you tell me where it is in our computer?

1 like
papa28x4's avatar

@amn I know this is an old question so my guess is that you eventually found out. But for anyone else who would like to know;

it can be found => vendor\laravel\ui\src\AuthRouteMethods.php (Laravel 7.0 & 8.0)

3 likes

Please or to participate in this conversation.