hassan ahmadi
hassan ahmadi

Reputation: 35

condition does not work on blade laravel 5.2

I want to load the panel if the user is logged in

and if the client is the master

But both files are loaded at runtime.

It does not run like a bet!

@if(Auth::check())
    @extends('panel')
@else
    @extends('master')
@endif

Upvotes: 1

Views: 72

Answers (4)

AddWeb Solution Pvt Ltd
AddWeb Solution Pvt Ltd

Reputation: 21681

You should try this:

@extends(isset(Auth::user()->id) ? 'panel' : 'master');

Upvotes: 0

shukshin.ivan
shukshin.ivan

Reputation: 11340

What do you want? To have different layouts for logged user and not logged one?

@extends(Auth::check() ? 'panel' : 'master')

You can't use two extends.

Two extends generate compiled views with code

<?php if(Auth::check()): ?>

<?php else: ?>

<?php endif; ?>

You can see, that extends are not here. But in the end of it -

<?php echo $__env->make('panel')... ->render();
<?php echo $__env->make('master')... ->render();

That's why use see them both.

Upvotes: 2

Misagh Laghaei
Misagh Laghaei

Reputation: 1369

Edit your extends definition :

Try this

@extends(auth()->check() ? 'panel' : 'master')

Upvotes: 0

user5633496
user5633496

Reputation:

Try use: auth()->check(), \Auth::check(), or remove all views in /var/www/html/laravel-master/storage/framework/views/.

If Auth::check() does not work, use Illuminate\Support\Facades\Auth::check() instead:

@if(Illuminate\Support\Facades\Auth::check())
    @extends('panel')
@else
    @extends('master')
@endif

Upvotes: 0

Related Questions