Example 9-21. The authorization-to-method mappings of authorizeResource()
classContactsControllerextendsController{publicfunction__construct() {// This call does everything you see in the methods below.// If you put this here, you can remove all authorize()// calls in the individual resource methods here.$this->authorizeResource(Contact::class); }publicfunctionindex() {$this->authorize('view',Contact::class); }publicfunctioncreate() {$this->authorize('create',Contact::class); }publicfunctionstore(Request $request) {$this->authorize('create',Contact::class); }publicfunctionshow(Contact $contact) {$this->authorize('view', $contact); }publicfunctionedit(Contact $contact) {$this->authorize('update', $contact); }publicfunctionupdate(Request $request,Contact $contact) {$this->authorize('update', $contact); }publicfunctiondestroy(Contact $contact) {$this->authorize('delete', $contact); }}