@@ -102,8 +102,6 @@ <h4><a name="artisan" href="#artisan">Artisan</a> <a href="http://laravel.com/do
102
102
// -v|vv|vvv Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
103
103
php artisan --verbose
104
104
105
- // Display the framework change list
106
- ?
107
105
// Remove the compiled class file
108
106
php artisan clear-compiled
109
107
// Display the current framework environment
@@ -118,8 +116,7 @@ <h4><a name="artisan" href="#artisan">Artisan</a> <a href="http://laravel.com/do
118
116
php artisan down
119
117
// Bring the application out of maintenance mode
120
118
php artisan up
121
- // Regenerate framework autoload files
122
- ?
119
+
123
120
// Optimize the framework for better performance
124
121
// --force Force the compiled class file to be written.
125
122
// --psr Do not optimize Composer dump-autoload.
@@ -1228,8 +1225,21 @@ <h6>Hashing <a href="http://laravel.com/docs/hashing" title="Hashing @ Laravel D
1228
1225
Hash::check('secretpassword', $hashedPassword);
1229
1226
Hash::needsRehash($hashedPassword);
1230
1227
</ 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
1233
1243
Auth::check();
1234
1244
// Get the currently authenticated user
1235
1245
Auth::user();
@@ -1255,16 +1265,51 @@ <h6>Authentication <a href="http://laravel.com/docs/authentication" title="Authe
1255
1265
Auth::onceBasic();
1256
1266
// Send a password reminder to a user
1257
1267
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
1259
1299
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)
1266
1304
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 >
1268
1313
1269
1314
< section class ="cmd-description grid-item ">
1270
1315
< 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