have you tried
@if(isset(Auth::user->id())
//this confirms that the user is logged in using the default Auth users method.
@extends("template/index")
@else
@extends("template/login")
@endif
However, this is how I did mine in a project awhile back
@if (isset(Auth::user()->id))
@include('layouts.admin')
@endif
So, if the user was logged in that meant they were an admin and it showed admin controls. Maybe you can just use include rather then extends to include that section based on your credentials.
Hope that helps!
I would not do an template control structure within a check like this. What you should do is have a route filter that checks for auth, and if they are not logged in redirect them to the appropriate page that is maintained specifically for that purpose. If the same content is on the un-authed page and authed page and you are only changing the template, then you can @include
that content from its own partial.
lordmilutin said:
I want do check simple condition and then decide what template should I extend. I want to do something like this:
@if(Auth::check()) @extends("template/index") @else @extends("template/login") @endif
But when I do, I get both templates extended ....
I use a ternary operator in the function args to do this, mainly for swapping out logged in vs logged out nav on content only pages that are accessible internally and externally that are the same content, having a whole separate page & route just adds to copy-n-paste maintenance.
So for you it would be :
@extends(Auth::user() ? 'template/index' : 'template/login');
I had the same exact issue, and using Auth::user()
with ternary operator did the trick. Thanks JeremyHutchings!!
JeremyHutchings said:
lordmilutin said:
I want do check simple condition and then decide what template should I extend. I want to do something like this:
@if(Auth::check()) @extends("template/index") @else @extends("template/login") @endif
But when I do, I get both templates extended ....
I use a ternary operator in the function args to do this, mainly for swapping out logged in vs logged out nav on content only pages that are accessible internally and externally that are the same content, having a whole separate page & route just adds to copy-n-paste maintenance.
So for you it would be :
@extends(Auth::user() ? 'template/index' : 'template/login');
Works like a charm, Thanks!
Laravel Blade template step by step instructions with source code http://phpclicks.com/laravel-blade-template/
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community