dynamitem
dynamitem

Reputation: 1679

Laravel 4 blade views

In my view there is an if function like this:

@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

Basically if the viewer is a guest, it'll display the specific data, else otherwise. I'm asking you, you see there is an:

@if (Auth::guest())

So, could I use something similar from my model?

Role.php

<?php

class Role extends Eloquent {

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

}

and the controller:

<?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.');
                    }
             }
}

Is it possible to do like if($roles == 5) or something like that in the view?

Upvotes: 0

Views: 493

Answers (1)

Laurence
Laurence

Reputation: 60068

Change

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

to

return View::make('admin.dash')->with('roles', $roles);

Upvotes: 1

Related Questions