0

在我看来,有一个这样的 if 函数:

@if ( Auth::guest() )

<li style="float: right;padding-right: 0">
  <ul class="nav">
    <li>
      <a href="{{ URL::to('register') }}">
        <i class="icon-black icon-plus">
        </i>

        <strong>
          Register
        </strong>
      </a>
    </li>
    <li>
      <a href="{{ URL::to('login') }}">
        <i class="icon-black icon-lock">
        </i>

        <strong>
          Log in
        </strong>
      </a>
    </li>
  </li>
</li>
</ul>

@else

<li class="divider-vertical">
</li>
<li style="float: right;padding-right: 0">
<div class="btn-group">
  <div class="btn btn-primary">
    <i class="icon-user">
    </i>
    {{ (Auth::user()->name) }}
  </div>

  <a class="btn btn-primary dropdown-toggle" data-toggle="dropdown" href="#">
    <span class="icon-caret-down">
    </span>
  </a>

  <ul class="dropdown-menu">
    <li>

      <a href="{{ URL::to('account/managment') }}">
        <i class="icon-user">
        </i>
        Account Managment  
      </a>

    </li>
    <li>

      <a href="{{ URL::to('account/managment/change_credentials') }}">
        <i class="icon-lock">
        </i>
        Change Password
      </a>

    </li>
    <li class="divider">
    </li>
    <li>

      <a href="{{ URL::to('account/logout') }}">
        <i class="icon-off">
        </i>
        Log out
      </a>

    </li>

  </ul>
</div>

@endif

基本上,如果观众是客人,它将显示特定数据,否则。我问你,你看有一个:

@if (Auth::guest())

那么,我可以使用与我的模型类似的东西吗?

角色.php

<?php

class Role extends Eloquent {

    public function user()
    {
        return $this->belongsToMany('User');
    }

}

和控制器:

<?php

class RoleController extends BaseController {

    public function get_role() {
$roles = Auth::user()->type;

            if ($roles == '5')
             {
               return View::make('admin.dash');
             } else {

               return Redirect::to('news/index')->with('danger', 'You either have insufficient permissions to access this page or your user credentials are not refreshed.');
                    }
             }
}

是否可以在视图中做类似if($roles == 5)或类似的事情?

4

1 回答 1

1

改变

return View::make('admin.dash');

return View::make('admin.dash')->with('roles', $roles);
于 2013-08-02T14:18:48.833 回答