I have some issue about Laravel Auth. I already make my own page with Laravel and now I want to add user login. So I used php artisan make:auth
and it went smoothly but. My auth doesn't show up on my index page. I think, it's because I already change Laravel's main page. And now, how can I display it on my own main page.
So Laravel Auth came with the Home Controller and with Route in web file. I already changed it to my main page which is welcome.blade but still can not see login and register bar at right top?
Controller
public function index()
{
return view('welcome');
}
Route
Route::get('welcome', 'HomeController@index')->name('welcome');
How can I call it Auth's register and login link to my main mage(welcome.blade)?
welcome.blade
<div class="flex-center position-ref full-height">
@if (Route::has('login'))
<div class="top-right links">
@auth
<a href="{{ url('welcome') }}">Home</a>
@else
<a href="{{ route('login') }}">Login</a>
@if (Route::has('register'))
<a href="{{ route('register') }}">Register</a>
@endif
@endauth
</div>
@endif
</div>
I am calling on page with the code above. But doesn't work?
You should try this:
Route::group( ['middleware' => 'auth' ], function()
{
Route::get('welcome', 'HomeController@index')->name('welcome');
});
Route::get('login', 'LoginController@showLogin')->name('login');
Route::get('register', 'RegisterController@register')->name('register');
If you want it only single routes. Just chain middleware('auth') at the end of your route. Example:
Route::get('welcome', 'HomeController@index')->name('welcome')->middleware('auth');
You can customize it.
You can group your routes with this middleware as suggested by saurabh dhariwal
On your edit. Make a route. And on that route controller return the view of your register page and login page. Simple as that
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.