简体   繁体   中英

How can I move the login behaviour from the /login URL to my home page in a Laravel application?

I am pretty new in PHP and moreover in Laravel framework (I came from Java ) and I have the following problem related to Laravel security.

I have correctly configured my Laravel login system so if I access to the page:

http://localhost:8000/login

I obtain my login page from where I can access to the restriced area of my portal. This is the standard Laravel login page.

My doubt is: can I take this behavior into my home page? Because I have to put the login into a custom login from into my home page (the one that is automatically opened launching http://localhost:8000/ ).

How can I do this?

From your question i understand that:

You are adding the login form in the homepage and not trying to provide the link to the login page from homepage.

If this is not your question i could delete my answer.

So, if you are using blade you could easily import the chunks of codes from login page.

More on Sub-view Here:

https://laravel.com/docs/5.3/blade#including-sub-views

Example:

login.blade.php

<div class="form">
    //your login form contents
</div>

homepage.blade.php

//your homepage codes

@include('login')

//rest of your homepage codes

Note:

The path to your subview is relative to resources/views/ .

ie If you have this folder structure like this:

|-resources
   |-views
      |-homepage.blade.php
      |-partials
          |-login.blade.php

then you will need to use:

@include('partials.login')

in your homepage.blade.php to use that view.

在web.php内,在路由末尾添加此路由

Route::get('/', 'Auth\AuthController@getLogin');

You can update routes file in laravel like below.

Basically your routes file is located in

YourProject/app/Http/routes.php

here you can copy the View(blade) / Controller of /login route to / . Like example shown below.

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

Replace the above one to

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

example above is without controller.

Hope it works!!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM