Part 29 - Authentication User Experience [How to Build a Blog with Laravel 5 Series]

preview_player
Показать описание
We have our authentication working now, and in this video we learn how to modify our user experience based on whether or not the current user is logged in or logged out.

If the user is logged in we will show our dropdown menu and if they are logged out we will display a simple button to login.

We use blade @if statements and our new Auth::check() helper to see if the user is logged in. If they are logged in then our Auth::check() will return true and execute the if statement, otherwise it will execute the else statement.

We will put the HTML needed for our dropdown in the first if statement clause, and we will put the button to login in the else clause.

To finish up our tutorial we want to make a customary friendly notification when the user is logged in. We will have the logged in menu say "Hello Name". To do this, we take advantage of our second helper Auth::user() and then we just access the property for each column name in the user database table.

Coming Up:
Forgot my Password functionality in our authentication tutorial.

--- CODE SNIPPETS ---

See if current user is logged in
Auth::check()

Get Logged in User's Info (returns null if not logged in)
Auth::user()

--- DOWNLOAD SOURCE CODE ---

--- MORE FROM THIS SERIES ---

--- FOLLOW ME ---

Subscribe for New Releases!

(ask me questions!)

--- QUESTIONS? ---

Leave a comment below and I or someone else can help you.
For quick questions you may also want to ask me on Twitter, I respond almost immediately.

Thanks for all your support!

---

Tags: Laravel 5.2 Framework Tutorial Easy to learn. Best tut about Laravel. Build a blog with Laravel Tutorial. Beginner tutorial. How to video. PHP framework easy best tutorial. Laravel 5 coding in PHP with Alex.
Рекомендации по теме
Комментарии
Автор

For your next series :
- a Forum ?
- a Social Network ?
- a Browser Management Game ?

Thanks for all Alex !

dadaarno
Автор

I am wondering how many people did all this before they go to the video? I did. It's a good way to test how you do it and how the teacher does it...and it was identical.

JohnnyMcCaffery
Автор

for newer laravel you can use @guest on blade instead of Auth::check as an in-built if then else with auth as a conditional

junex
Автор

to give the login button the same styling, you can use:
<li>
<a href="{{ route('auth.login') }}">Login</a>
</li>

hamidelabassi
Автор

Jacurtis very good video thanks again waiting for the next series with no patience

cvetomirvasilev
Автор

just a tip, You can use php artisan make:auth to generate login and register view automatically.

justinx
Автор

Hey first things first: Great Job! Thank you for the amazing tutorial, I learned so much in the past days! Next steps are to apply my new knowledge for my own little project. However I a missing one small feature: How to allow to edit/delete logged in users only their own blog posts?

Mamulasa
Автор

Mr.alex when i add if statment in navbar the output in index page was that

FatalErrorException in Grammar.php line 151:
Maximum function nesting level of '100' reached, aborting!

maheralmasalati
Автор

Hi Alex! First, thank you very much for these helpful tutorials! But I have a question about showing the name in the view via the model, because in the 'What the hell is MVC' you talked about views, and that they must NOT communicate directly to models, like you do with Auth::user? Isn't Auth a model?

RubendeMan
Автор

For those who has error " Maximum function nesting level of '100' reached, aborting! "
I found the solution =>
open bootstrap /autoload and add this line at the end
ini_set('xdebug.max_nesting_level', 120);

Thank you.

mohamedmamdouh
Автор

What could be interesting but, probably beyond the scope of this tutorial. Allow registered users to edit / delete ONLY their posts.

Osteele
Автор

hello,
I am new with laravel ...so i have a problem here :
ErrorException in Encrypter.php line 144:
The payload is invalid.
is occurred due to i try to decrypt back the password of authenticated user ...
so would you mind helping me this ?

vannatrin
Автор

Hi, I go a error on Home/blog/about/contact but not in /posts

when i put the @if (Auth::check()) in the navigation.blade.php I go the

FatalErrorException in Str.php line 69:
Maximum function nesting level of '100' reached, aborting!

My laravel version is 5.2.41

can you help me plz.

kennychansin
Автор

ErrorException thrown with message "Missing required parameters for [Route: password.reset] [URI: password/reset/{token}]. (View:

How to solve this error?

and I have created emails.password file but the view is coming from Illuminate framework

kevinpatel
Автор

Hi there i've found a little bit of a snag but the auth:check() creates a nesting error when placed it in a partial like the nav .. this is a known error on the laracast forum but would you happen to know how to fix this or maybe of another way to check if a user is logged in? thanks

shared-knowledge
Автор

Hi, I have trouble when I push button login, fatal error said : FatalErrorException in Grammar.php line 151:
Maximum function nesting level of '100' reached, aborting!


So, what must I have to do for fix it..

Thanks.

ariirawan
Автор

Here the code for make a logout link in Laravel 5.5

<a class="dropdown-item" href="{{ route('logout')}}"


<form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;">
{{ csrf_field() }}
</form>

paularie