Laravel authorization example
Policy là các class quản lý tuyệt vời không thể trong phân quyền tác động đến một Model hoặc tài nguyên nào đó. Ví dụ, nếu chương trình của bạn là một blog, bạn thường xuyên rất sở hữu không thể một model Post và một policy là postpolicy để phân quyền các hành động người dùng như là có thể tạo hay cập nhật các nội dung bài viết đích . Một policy muốn dùng tốt nhất nên dễ được đăng ký, AuthServiceProvider được đưa vào trong project Laravel chứa một thuộc tính policies để map Eloquent model với các policy tương ứng với sâu Laravel authorization example.
<?php
namespace AppProviders;
use AppPost;
use AppPoliciesPostPolicy;
use IlluminateSupportFacadesGate;
use IlluminateFoundationSupportProvidersAuthServiceProvider as ServiceProvider;
class AuthServiceProvider extends ServiceProvider
/**
* The policy mappings for the application.
*
* @var array
*/
protected $policies = [
Post::class => PostPolicy::class,
];
/**
* Register any application authentication / authorization services.
*
* @return void
*/
public function boot()
$this->registerPolicies();
//
sâu

Laravel authorization middleware - Định nghĩa tường tận về LA