This repository has been archived by the owner on Aug 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
authorization.html
99 lines (93 loc) · 28.3 KB
/
authorization.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Authorization | Sanjab</title>
<meta name="generator" content="VuePress 1.5.4">
<link rel="icon" href="/images/favicon.ico">
<meta name="description" content="Sanjab is an admin package for laravel framework. create admin panels quick and extendiable.">
<meta property="og:site_name" content="Sanjab">
<meta property="og:title" content="Authorization">
<meta property="og:type" content="website">
<meta property="og:url" content="/authorization.html">
<meta name="twitter:title" content="Authorization">
<meta name="twitter:url" content="/authorization.html">
<meta name="twitter:card" content="summary_large_image">
<link rel="preload" href="/assets/css/0.styles.2e8fc617.css" as="style"><link rel="preload" href="/assets/js/app.bb080b10.js" as="script"><link rel="preload" href="/assets/js/3.0ca36dc4.js" as="script"><link rel="preload" href="/assets/js/40.667cd531.js" as="script"><link rel="prefetch" href="/assets/js/10.f2fbcc00.js"><link rel="prefetch" href="/assets/js/11.a88150f7.js"><link rel="prefetch" href="/assets/js/12.3f4fc49f.js"><link rel="prefetch" href="/assets/js/13.2f7bbe92.js"><link rel="prefetch" href="/assets/js/14.f69c3be7.js"><link rel="prefetch" href="/assets/js/15.146fd77b.js"><link rel="prefetch" href="/assets/js/16.7040661a.js"><link rel="prefetch" href="/assets/js/17.10c67635.js"><link rel="prefetch" href="/assets/js/18.b258fc52.js"><link rel="prefetch" href="/assets/js/19.0d164613.js"><link rel="prefetch" href="/assets/js/20.2cf36932.js"><link rel="prefetch" href="/assets/js/21.8f19317a.js"><link rel="prefetch" href="/assets/js/22.3dc04c9b.js"><link rel="prefetch" href="/assets/js/23.7d93154e.js"><link rel="prefetch" href="/assets/js/24.d10068db.js"><link rel="prefetch" href="/assets/js/25.ecd8acc3.js"><link rel="prefetch" href="/assets/js/26.5ae91a18.js"><link rel="prefetch" href="/assets/js/27.1ae60bea.js"><link rel="prefetch" href="/assets/js/28.1dd28706.js"><link rel="prefetch" href="/assets/js/29.8c489115.js"><link rel="prefetch" href="/assets/js/30.effa9b52.js"><link rel="prefetch" href="/assets/js/31.5f330bfc.js"><link rel="prefetch" href="/assets/js/32.4ac193d2.js"><link rel="prefetch" href="/assets/js/33.afce904a.js"><link rel="prefetch" href="/assets/js/34.29769f89.js"><link rel="prefetch" href="/assets/js/35.85aef861.js"><link rel="prefetch" href="/assets/js/36.5b05176c.js"><link rel="prefetch" href="/assets/js/37.40a67162.js"><link rel="prefetch" href="/assets/js/38.0585aaff.js"><link rel="prefetch" href="/assets/js/39.085c73ff.js"><link rel="prefetch" href="/assets/js/4.fb05333f.js"><link rel="prefetch" href="/assets/js/41.9bf9596e.js"><link rel="prefetch" href="/assets/js/42.7bf6bc5a.js"><link rel="prefetch" href="/assets/js/43.dbde9849.js"><link rel="prefetch" href="/assets/js/44.a1a7fab3.js"><link rel="prefetch" href="/assets/js/45.af6c374b.js"><link rel="prefetch" href="/assets/js/46.22ab45aa.js"><link rel="prefetch" href="/assets/js/47.095fc7de.js"><link rel="prefetch" href="/assets/js/48.fafabd31.js"><link rel="prefetch" href="/assets/js/49.8b56a6bd.js"><link rel="prefetch" href="/assets/js/5.57d9df4b.js"><link rel="prefetch" href="/assets/js/50.523e948d.js"><link rel="prefetch" href="/assets/js/51.2b0f3efa.js"><link rel="prefetch" href="/assets/js/6.3a56987d.js"><link rel="prefetch" href="/assets/js/7.8bfd5ac9.js"><link rel="prefetch" href="/assets/js/8.3d2834af.js"><link rel="prefetch" href="/assets/js/9.e3de8168.js"><link rel="prefetch" href="/assets/js/vendors~docsearch.26dc1fe9.js">
<link rel="stylesheet" href="/assets/css/0.styles.2e8fc617.css">
</head>
<body>
<div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><img src="/images/logo.svg" alt="Sanjab" class="logo"> <span class="site-name can-hide">Sanjab</span></a> <div class="links"><form id="search-form" role="search" class="algolia-search-wrapper search-box"><input id="algolia-search-input" class="search-query"></form> <nav class="nav-links can-hide"><div class="nav-item"><a href="https://discord.gg/kwuTZQd" target="_blank" rel="noopener noreferrer" class="nav-link external">
Discussion
<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div> <a href="https://github.com/sanjabteam/sanjab" target="_blank" rel="noopener noreferrer" class="repo-link">
GitHub
<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="https://discord.gg/kwuTZQd" target="_blank" rel="noopener noreferrer" class="nav-link external">
Discussion
<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div> <a href="https://github.com/sanjabteam/sanjab" target="_blank" rel="noopener noreferrer" class="repo-link">
GitHub
<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></nav> <ul class="sidebar-links"><li><a href="/" aria-current="page" class="sidebar-link">Sanjab</a></li><li><a href="/install.html" class="sidebar-link">Installation</a></li><li><a href="/crud.html" class="sidebar-link">CRUD</a></li><li><a href="/setting.html" class="sidebar-link">Setting</a></li><li><section class="sidebar-group collapsable depth-0"><a href="/widgets" class="sidebar-heading clickable"><span>Widgets</span> <span class="arrow right"></span></a> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><a href="/cards" class="sidebar-heading clickable"><span>Cards</span> <span class="arrow right"></span></a> <!----></section></li><li><a href="/actions.html" class="sidebar-link">Actions</a></li><li><a href="/localization.html" class="sidebar-link">Localization</a></li><li><a href="/authorization.html" aria-current="page" class="active sidebar-link">Authorization</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/authorization.html#creating-a-super-admin" class="sidebar-link">Creating a Super Admin</a></li><li class="sidebar-sub-header"><a href="/authorization.html#seeding-database" class="sidebar-link">Seeding Database</a></li><li class="sidebar-sub-header"><a href="/authorization.html#model-policies" class="sidebar-link">Model Policies</a></li><li class="sidebar-sub-header"><a href="/authorization.html#custom-permissions" class="sidebar-link">Custom Permissions</a></li></ul></li><li><a href="/compile.html" class="sidebar-link">Custom compile</a></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="authorization"><a href="#authorization" class="header-anchor">#</a> Authorization</h1> <ul><li><a href="#creating-a-super-admin">Creating a Super Admin</a></li> <li><a href="#seeding-database">Seeding Database</a></li> <li><a href="#model-policies">Model Policies</a></li> <li><a href="#custom-permissions">Custom Permissions</a></li></ul> <p>Authorization in sanjab is based on <a href="https://github.com/JosephSilber/bouncer" target="_blank" rel="noopener noreferrer">Bouncer<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a>.</p> <p>You can set permissions for roles in Roles panel.</p> <h2 id="creating-a-super-admin"><a href="#creating-a-super-admin" class="header-anchor">#</a> Creating a Super Admin</h2> <p>Super admin is a root admin that can set roles/permissions for other users.
To create a new super admin run following command.</p> <div class="language-bash extra-class"><pre class="language-bash"><code>php artisan sanjab:make:admin
</code></pre></div><p>Command will ask you the email of the user to convert an existing user to super admin.</p> <h2 id="seeding-database"><a href="#seeding-database" class="header-anchor">#</a> Seeding Database</h2> <p>You can create roles/permissions with <a href="https://laravel.com/docs/seeding" target="_blank" rel="noopener noreferrer">database seeders<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a>. check <a href="https://github.com/JosephSilber/bouncer" target="_blank" rel="noopener noreferrer">Bouncer docs<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a> for more informations.</p> <p>Example:</p> <div class="language-php extra-class"><pre class="language-php"><code><span class="token keyword">use</span> <span class="token package">Bouncer</span><span class="token punctuation">;</span>
<span class="token keyword">use</span> <span class="token package">Silber<span class="token punctuation">\</span>Bouncer<span class="token punctuation">\</span>Database<span class="token punctuation">\</span>Role</span><span class="token punctuation">;</span>
<span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span> Role<span class="token punctuation">:</span><span class="token punctuation">:</span><span class="token function">where</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'name'</span><span class="token punctuation">,</span> <span class="token single-quoted-string string">'admin'</span><span class="token punctuation">)</span><span class="token operator">-</span><span class="token operator">></span><span class="token function">exists</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
Role<span class="token punctuation">:</span><span class="token punctuation">:</span><span class="token function">create</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token single-quoted-string string">'name'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token single-quoted-string string">'admin'</span><span class="token punctuation">,</span> <span class="token single-quoted-string string">'title'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token single-quoted-string string">'Normal Admin'</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
Bouncer<span class="token punctuation">:</span><span class="token punctuation">:</span><span class="token function">allow</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'admin'</span><span class="token punctuation">)</span><span class="token operator">-</span><span class="token operator">></span><span class="token function">to</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'access_sanjab'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Allow access to admin panel</span>
Bouncer<span class="token punctuation">:</span><span class="token punctuation">:</span><span class="token function">allow</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'admin'</span><span class="token punctuation">)</span><span class="token operator">-</span><span class="token operator">></span><span class="token function">to</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'update_setting_general'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Allow access to general setting</span>
Bouncer<span class="token punctuation">:</span><span class="token punctuation">:</span><span class="token function">allow</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'admin'</span><span class="token punctuation">)</span><span class="token operator">-</span><span class="token operator">></span><span class="token function">to</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'update_setting_seo'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// allow access to seo setting</span>
<span class="token keyword">foreach</span> <span class="token punctuation">(</span><span class="token punctuation">[</span>
\<span class="token package">App<span class="token punctuation">\</span>Category</span><span class="token punctuation">:</span><span class="token punctuation">:</span><span class="token keyword">class</span><span class="token punctuation">,</span>
\<span class="token package">App<span class="token punctuation">\</span>Product</span><span class="token punctuation">:</span><span class="token punctuation">:</span><span class="token keyword">class</span><span class="token punctuation">,</span>
\<span class="token package">App<span class="token punctuation">\</span>Order</span><span class="token punctuation">:</span><span class="token punctuation">:</span><span class="token keyword">class</span><span class="token punctuation">,</span>
\<span class="token package">App<span class="token punctuation">\</span>Comment</span><span class="token punctuation">:</span><span class="token punctuation">:</span><span class="token keyword">class</span><span class="token punctuation">,</span>
<span class="token punctuation">]</span> <span class="token keyword">as</span> <span class="token variable">$model</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token comment">// Allow manage CRUD with these models (only with default permission keys)</span>
Bouncer<span class="token punctuation">:</span><span class="token punctuation">:</span><span class="token function">allow</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'admin'</span><span class="token punctuation">)</span><span class="token operator">-</span><span class="token operator">></span><span class="token function">toManage</span><span class="token punctuation">(</span><span class="token variable">$model</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
Bouncer<span class="token punctuation">:</span><span class="token punctuation">:</span><span class="token function">assign</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'admin'</span><span class="token punctuation">)</span><span class="token operator">-</span><span class="token operator">></span><span class="token function">to</span><span class="token punctuation">(</span><span class="token variable">$adminUser</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span> Role<span class="token punctuation">:</span><span class="token punctuation">:</span><span class="token function">where</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'name'</span><span class="token punctuation">,</span> <span class="token single-quoted-string string">'writer'</span><span class="token punctuation">)</span><span class="token operator">-</span><span class="token operator">></span><span class="token function">exists</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
Role<span class="token punctuation">:</span><span class="token punctuation">:</span><span class="token function">create</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token single-quoted-string string">'name'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token single-quoted-string string">'writer'</span><span class="token punctuation">,</span> <span class="token single-quoted-string string">'title'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token single-quoted-string string">'Writer'</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
Bouncer<span class="token punctuation">:</span><span class="token punctuation">:</span><span class="token function">allow</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'writer'</span><span class="token punctuation">)</span><span class="token operator">-</span><span class="token operator">></span><span class="token function">to</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'access_sanjab'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Allow access to admin panel</span>
Bouncer<span class="token punctuation">:</span><span class="token punctuation">:</span><span class="token function">allow</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'writer'</span><span class="token punctuation">)</span><span class="token operator">-</span><span class="token operator">></span><span class="token function">to</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'create'</span><span class="token punctuation">,</span> \<span class="token package">App<span class="token punctuation">\</span>Article</span><span class="token punctuation">:</span><span class="token punctuation">:</span><span class="token keyword">class</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// allow writers to create articles.</span>
Bouncer<span class="token punctuation">:</span><span class="token punctuation">:</span><span class="token function">assign</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'writer'</span><span class="token punctuation">)</span><span class="token operator">-</span><span class="token operator">></span><span class="token function">to</span><span class="token punctuation">(</span><span class="token variable">$writerUser</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre></div><h2 id="model-policies"><a href="#model-policies" class="header-anchor">#</a> Model Policies</h2> <p>Sanjab supports Eloquent <a href="https://laravel.com/docs/authorization#creating-policies" target="_blank" rel="noopener noreferrer">policies<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a> as well.</p> <p>So you can check permissions runtime.</p> <p>Example:</p> <div class="language-php extra-class"><pre class="language-php"><code><span class="token keyword">class</span> <span class="token class-name">ArticlePolicy</span>
<span class="token punctuation">{</span>
<span class="token keyword">use</span> <span class="token package">HandlesAuthorization</span><span class="token punctuation">;</span>
<span class="token comment">/**
* Determine whether the user can update the model.
*
* @param \Illuminate\Foundation\Auth\User $user
* @param \App\Article $article
* @return mixed
*/</span>
<span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function">update</span><span class="token punctuation">(</span>User <span class="token variable">$user</span><span class="token punctuation">,</span> Article <span class="token variable">$article</span><span class="token punctuation">)</span>
<span class="token punctuation">{</span>
<span class="token keyword">return</span> <span class="token variable">$user</span><span class="token operator">-</span><span class="token operator">></span><span class="token function">isA</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'super_admin'</span><span class="token punctuation">)</span> <span class="token operator">||</span> <span class="token variable">$user</span><span class="token operator">-</span><span class="token operator">></span><span class="token property">id</span> <span class="token operator">==</span> <span class="token variable">$article</span><span class="token operator">-</span><span class="token operator">></span><span class="token property">user_id</span><span class="token punctuation">;</span> <span class="token comment">// Only super admins can edit all articles. Others only can edit their own articles.</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre></div><h2 id="custom-permissions"><a href="#custom-permissions" class="header-anchor">#</a> Custom Permissions</h2> <p>If you want to define your custom permission be editable on roles panel then go to <code>AppServiceProvider.php</code> and use the following function to submit your custom permission.</p> <div class="language-php extra-class"><pre class="language-php"><code><span class="token keyword">use</span> <span class="token package">Sanjab</span><span class="token punctuation">;</span>
<span class="token keyword">use</span> <span class="token package">Sanjab<span class="token punctuation">\</span>Helpers<span class="token punctuation">\</span>PermissionItem</span><span class="token punctuation">;</span>
<span class="token keyword">class</span> <span class="token class-name">AppServiceProvider</span> <span class="token keyword">extends</span> <span class="token class-name">ServiceProvider</span>
<span class="token punctuation">{</span>
<span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function">boot</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token punctuation">{</span>
Sanjab<span class="token punctuation">:</span><span class="token punctuation">:</span><span class="token function">addPermission</span><span class="token punctuation">(</span>
PermissionItem<span class="token punctuation">:</span><span class="token punctuation">:</span><span class="token function">create</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'Permission Group'</span><span class="token punctuation">)</span>
<span class="token operator">-</span><span class="token operator">></span><span class="token function">addPermission</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'Permission Title'</span><span class="token punctuation">,</span> <span class="token single-quoted-string string">'unique_permission_name'</span><span class="token punctuation">)</span>
<span class="token operator">-</span><span class="token operator">></span><span class="token function">addPermission</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'Another Permission Title'</span><span class="token punctuation">,</span> <span class="token single-quoted-string string">'create'</span><span class="token punctuation">,</span> \<span class="token package">App<span class="token punctuation">\</span>YourModel</span><span class="token punctuation">:</span><span class="token punctuation">:</span><span class="token keyword">class</span><span class="token punctuation">)</span>
<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre></div><p>You can also set order in checkbox groups.</p> <h4 id="order"><a href="#order" class="header-anchor">#</a> order</h4> <p><code>type: int</code></p> <p>Order in checkbox groups.</p></div> <footer class="page-edit"><div class="edit-link"><a href="https://github.com/sanjabteam/docs/edit/master/docs/authorization.md" target="_blank" rel="noopener noreferrer">Help us improve this page!</a> <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></div> <!----></footer> <div class="page-nav"><p class="inner"><span class="prev">
←
<a href="/localization.html" class="prev">
Localization
</a></span> <span class="next"><a href="/compile.html">
Custom compile
</a>
→
</span></p></div> </main></div><div class="global-ui"><!----></div></div>
<script src="/assets/js/app.bb080b10.js" defer></script><script src="/assets/js/3.0ca36dc4.js" defer></script><script src="/assets/js/40.667cd531.js" defer></script>
</body>
</html>