Skip to content

Commit 8a235c2

Browse files
committed
add Authorization section
1 parent 02f4909 commit 8a235c2

File tree

1 file changed

+59
-14
lines changed

1 file changed

+59
-14
lines changed

index.html

Lines changed: 59 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,6 @@ <h4><a name="artisan" href="#artisan">Artisan</a> <a href="http://laravel.com/do
102102
// -v|vv|vvv Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
103103
php artisan --verbose
104104

105-
// Display the framework change list
106-
?
107105
// Remove the compiled class file
108106
php artisan clear-compiled
109107
// Display the current framework environment
@@ -118,8 +116,7 @@ <h4><a name="artisan" href="#artisan">Artisan</a> <a href="http://laravel.com/do
118116
php artisan down
119117
// Bring the application out of maintenance mode
120118
php artisan up
121-
// Regenerate framework autoload files
122-
?
119+
123120
// Optimize the framework for better performance
124121
// --force Force the compiled class file to be written.
125122
// --psr Do not optimize Composer dump-autoload.
@@ -1228,8 +1225,21 @@ <h6>Hashing <a href="http://laravel.com/docs/hashing" title="Hashing @ Laravel D
12281225
Hash::check('secretpassword', $hashedPassword);
12291226
Hash::needsRehash($hashedPassword);
12301227
</pre>
1231-
<h6>Authentication <a href="http://laravel.com/docs/authentication" title="Authentication @ Laravel Docs"><i class="icon-file-text"></i></a></h6>
1232-
<pre class="prettyprint lang-php">// Determine if the current user is authenticated
1228+
1229+
<h6>Encryption</h6>
1230+
<pre class="prettyprint lang-php">Crypt::encrypt('secretstring');
1231+
Crypt::decrypt($encryptedString);
1232+
Crypt::setMode('ctr');
1233+
Crypt::setCipher($cipher);
1234+
</pre>
1235+
1236+
</section>
1237+
1238+
<section class="cmd-description grid-item">
1239+
<h4><a name="auth" href="#auth">Auth</a></h4>
1240+
1241+
<h6>Authentication <a href="http://laravel.com/docs/authentication" title="Authentication @ Laravel Docs"><i class="icon-file-text"></i></a></h6>
1242+
<pre class="prettyprint lang-php">// Determine if the current user is authenticated
12331243
Auth::check();
12341244
// Get the currently authenticated user
12351245
Auth::user();
@@ -1255,16 +1265,51 @@ <h6>Authentication <a href="http://laravel.com/docs/authentication" title="Authe
12551265
Auth::onceBasic();
12561266
// Send a password reminder to a user
12571267
Password::remind($credentials, function($message, $user){});
1258-
</pre>
1268+
</pre>
1269+
1270+
<h6>Authorization <a href="http://laravel.com/docs/5.1/authorization" title="Authorization @ Laravel Docs"><i class="icon-file-text"></i></a></h6>
1271+
<pre class="prettyprint lang-php">
1272+
// Define abilities
1273+
Gate::define('update-post', 'Class@method');
1274+
Gate::define('update-post', function ($user, $post) {...});
1275+
// Passing multiple argument
1276+
Gate::define('delete-comment', function ($user, $post, $comment) {});
1277+
1278+
// Check abilities
1279+
Gate::denies('update-post', $post);
1280+
Gate::allows('update-post', $post);
1281+
Gate::check('update-post', $post);
1282+
// Specified a user for checking
1283+
Gate::forUser($user)->allows('update-post', $post);
1284+
// Through User model, using Authorizable trait
1285+
User::find(1)->can('update-post', $post);
1286+
User::find(1)->cannot('update-post', $post);
1287+
1288+
// Intercepting Authorization Checks
1289+
Gate::before(function ($user, $ability) {});
1290+
Gate::after(function ($user, $ability) {});
1291+
1292+
// Chekcing in Blade template
1293+
@can('update-post', $post)
1294+
@endcan
1295+
// with else
1296+
@can('update-post', $post)
1297+
@else
1298+
@endcan
12591299

1260-
<h6>Encryption</h6>
1261-
<pre class="prettyprint lang-php">Crypt::encrypt('secretstring');
1262-
Crypt::decrypt($encryptedString);
1263-
Crypt::setMode('ctr');
1264-
Crypt::setCipher($cipher);
1265-
</pre>
1300+
// Generate a Policy
1301+
php artisan make:policy PostPolicy
1302+
// `policy` helper function
1303+
policy($post)->update($user, $post)
12661304

1267-
</section>
1305+
// Controller Authorization
1306+
$this->authorize('update', $post);
1307+
// for $user
1308+
$this->authorizeForUser($user, 'update', $post);
1309+
1310+
</pre>
1311+
1312+
</section>
12681313

12691314
<section class="cmd-description grid-item">
12701315
<h4><a name="mail" href="#mail">Mail</a> <a href="http://laravel.com/docs/mail" title="Mail @ Laravel Docs"><i class="icon-file-text"></i></a></h4>

0 commit comments

Comments
 (0)