dimanche 29 septembre 2019

Whats the difference between @if and @can in laravel

Were making a project with different users. I noticed that I can use @if to prevent specific user from a specific function but I can also use @can. Can someone tell me what are thier differences. I did not register any policies in AuthServiceProvider but I can still use @can method. I'm just referring to the type of user. I'll show you some code.

Can

   @can($global_user->role != 0)
            <li class="">
              <a href="" onclick="return LoadingOverlay();">
                <i class="fa fa-list"></i>
                <span>Issue Tracker</span>
              </a>
            </li>
  @endcan

If

   @if($global_user->role != 0)

        <li class="">
          <a href="" onclick="return LoadingOverlay();">
            <i class="fa fa-child"></i>
            <span>Students</span>
          </a>
        </li>
@endif

Edit: Can I also use @can inside @if statements like this?

    @if($global_user->role != 0)
        <li class="treeview
            
            
            ">
          <a href="#">
            <i class="fa fa-bug"></i> <span>System Issues</span>
            <span class="pull-right-container">
              <i class="fa fa-angle-left pull-right"></i>
            </span>
          </a>
          <ul class="treeview-menu">

            <li class="">
              <a href="" onclick="return LoadingOverlay();">
                <i class="fa fa-edit"></i>
                <span>Report an Issue</span>
              </a>
            </li>


            @can($global_user->role != 3)
            <li class="">
              <a href="" onclick="return LoadingOverlay();">
                <i class="fa fa-list"></i>
                <span>Issue Tracker</span>
              </a>
            </li>
            @endcan


          </ul>
        </li>
        @endif


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2mVVgky
via IFTTT

Aucun commentaire:

Enregistrer un commentaire