title: How to use Authority package for Laravel
body: <p>After some searching, I succesfully installed the <a href="https://github.com/machuga/authority-l4" rel="nofollow noreferrer">Authority-l4</a> package to use for my Laravel project. The docs are clear but small (not much info/examples). This is what my config file looks like atm:</p>
  <pre><code>return array[
  
      'initialize' =&gt; function($authority) {
          $user = $authority-&gt;getCurrentUser();
  
          $authority-&gt;addAlias('manage', ['create', 'read', 'update', 'delete']);
  
          if($user-&gt;hasRole('admin')) {
              //Admin can manage all resources
              $authority-&gt;allow('manage', 'all');
          }
  
          // User can manage his own post
          Authority::allow('manage', 'User', function($self, $user){
              return $self-&gt;getCurrentUser()-&gt;id === $user-&gt;id;
          });
  
          // User can manage his own post
          Authority::allow('manage', 'Post', function($self, $post){
              return $self-&gt;getCurrentUser()-&gt;id === $post-&gt;id;
          });
      }
  
  ];
  </code></pre>
  <p>I have some questions about this:</p>
  <ol>
  <li>How to add a role to a user? <code>hasRole()</code> exists, why not <code>setRole()</code>?</li>
  <li>I noticed nothing gets saved into the database, isn't this better?</li>
  <li>How do I use my database with Authority? Could someone give me a head start, I've been strugling four hours now.</li>
  <li>In some articles they say that the class <code>Role</code> should be changed to have many permissions instead of a user having many permissions, isn't this better?</li>
  </ol>
  <p>Probably I'm thinking way to difficult about this package, searching the internet doesn't help either. Any help is appreciated!</p>