2016-06-20 22 views

回答

6

Laravel提供了一种简单的方法来检查用户是否已登录在通过使用门面Auth::check()

if (Auth::check()) { 
    // The user is logged in... 
} 

关于翻译,你可以点击这里:Localization

的结构是这样定义的,按照文件:

/resources 
    /lang 
     /en 
      messages.php 
     /es 
      messages.php 

Laravel还提供了一种简单的方法来翻译使用的短语trans('string.to.translate'),这里可以看到trans()

在messages.php中(在两个lang目录中),必须设置转换字符串。在en/messages.php

return [ 
     'welcome' => 'Welcome' 
    ]; 

es/messages.php

return [ 
     'welcome' => 'Bienvenido' 
    ]; 

有了这两个,你可以做你的应用程序下面的例子:

// Get the user locale, for the sake of clarity, I'll use a fixed string. 
    // Make sure is the same as the directory under lang. 
    App::setLocale('en'); 

内,您的view

// Using blade, we check if the user is logged in. 
    // If he is, we show 'Welcome" in the menu. If the lang is set to 
    // 'es', then it will show "Bienvenido". 
    @if (Auth::check()) 
     <ul> 
      <li> {{ trans('messages.welcome') }} </li> 
     </ul> 
    @endif