Laravel - 页面上的Auth错误

时间:2015-05-26 19:21:52

标签: laravel-4

如果我想测试我的Auth页面,我会收到此错误:

Trying to get property of non-object (View: C:\xampp\htdocs\system\app\views\home.blade.php)

这是在我的home.blade.php页面上:

<?php
   $username = Auth::user()->username;
   $id       = Auth::id();
   if (Auth::check()) {
?>

Hey, if you see this, than you have been logged in!
<a href="{{ URL::to('logout') }}">Logout</a>

    <?php
    } else {
    ?>
    You have to be logged in!
    <?php
    }
    ?>

屏幕错误:http://prntscr.com/79pix0

但我该如何解决这个问题呢?

1 个答案:

答案 0 :(得分:1)

您正在使用刀片模板引擎,为什么使用php thags呢?

如果要显示值,可以执行以下操作:

@if (Auth::check())

Hey,{{ Auth::user()->username }} if you see this, than you have been logged in!

<a href="{{ URL::to('logout') }}">Logout</a>

@else

    You have to be logged in!

@endif

希望这有助于你!