I am building a store so i could learn laravel. Like most stores, users can add items to a cart but cannot checkout until they register. How do i have the same route return a user name when authorized and a nothing when an authorized. This seemed very easy to me at first:
@if(Auth::guest())
Nothing || or login/register buttons
@else
{{ Auth::user()->name }}
@endif
That works well when you have content that should only be visible to loyal users but for a store, you need users to see whats there to offer.
The problem is that, in my home controller, i need to add middleware auth in the constructor function so that Route::get('/',HomeController@index);
returns a view and in the view use @if(Auth::guest()) ...
, but adding this middleware means this route is not accessible if the user is not Authenticated and without it you get this issue.
So how do i have the same root route with Authenticated user data(if authenticated)
without blocking the route from unauthenticated users?
auth
middleware on any public route, use the@if @else
block as mentioned in your question. Im not sure what you question is really, The issue in the question you linked is about a different middleware,web
– Stevephp artisan make:auth
works if you have public data and auth only data. In this case, all data is public but a user may own an account to get more access e.g checkout – user3533087