<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Uzair Khan</title>
    <description>The latest articles on Forem by Uzair Khan (@uzairjan).</description>
    <link>https://forem.com/uzairjan</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F96764%2F92a40fa8-4265-4152-a95a-753dd5edadfe.jpeg</url>
      <title>Forem: Uzair Khan</title>
      <link>https://forem.com/uzairjan</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/uzairjan"/>
    <language>en</language>
    <item>
      <title>Using Laratrust Permission and Roles Other Than Users Relation</title>
      <dc:creator>Uzair Khan</dc:creator>
      <pubDate>Tue, 23 Jun 2020 06:20:13 +0000</pubDate>
      <link>https://forem.com/uzairjan/using-laratrust-permission-and-roles-other-than-users-relation-4e98</link>
      <guid>https://forem.com/uzairjan/using-laratrust-permission-and-roles-other-than-users-relation-4e98</guid>
      <description>&lt;p&gt;Laratrust is a laravel package that lets you handle very easily roles and permission inside your application.&lt;br&gt;
laratrust by default make use of users relation but sometimes you wish not to use users relation in order to do so there are few steps to follow.&lt;/p&gt;

&lt;p&gt;step 1: install the package using composer.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   composer require santigarcor/laratrust
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;step 2: public the configuration files.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   php artisan vendor:publish --tag="laratrust"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;step: 3 Now before setting up laratrust you have to make a few changes to config/laratrust.php in laratust.php file make changes to tables array like so&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    'tables' =&amp;gt; [
        'roles' =&amp;gt; 'roles',
        'permissions' =&amp;gt; 'permissions',
        'teams' =&amp;gt; 'teams',
        'role_user' =&amp;gt; 'role_admin',
        'permission_user' =&amp;gt; 'permission_admin',
        'permission_role' =&amp;gt; 'permission_role',
     ],
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Note: do not change keys of tables array let it be as it is.&lt;/p&gt;

&lt;p&gt;step: 4 And now a slight change to the foreign keys array instead of using user_id it should now be admin_id like so.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;         'foreign_keys' =&amp;gt; [
               'user' =&amp;gt; 'admin_id',
               'role' =&amp;gt; 'role_id',
               'permission' =&amp;gt; 'permission_id',
               'team' =&amp;gt; 'team_id',
              ],
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;now you are all set to use laratrust with admin table instead of users table. &lt;/p&gt;

&lt;p&gt;Run the following artisan command to setup your laratrust migration.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; php artisan laratrust:setup
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;in migration of laratrust you would be able to see that migration is setup for admin table now simply migrate using.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; php artisan migrate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;and that’s all for using laratrust with a different relation than users.&lt;/p&gt;

&lt;p&gt;For further details please go to laratrust official site &lt;a href="https://laratrust.santigarcor.me"&gt;https://laratrust.santigarcor.me&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thank you&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>laratrust</category>
      <category>php</category>
      <category>roles</category>
    </item>
  </channel>
</rss>
