Laravel 9 保姆級視頻教程,想學(xué)不會都難!進入學(xué)習(xí)
經(jīng)過多年開發(fā),56 次發(fā)布,130 萬下載,并且超過 2800 的主動關(guān)注 Bouncer 終于來到了 1.0 版本。 在相當長的一段時間里,它一直非??煽亢头€(wěn)定,并被世界各地無數(shù)的 app 用于生產(chǎn)。
這是我個人的更新,包含了我多年來的一些思考 —— 從最初到最終發(fā)行。關(guān)于如何每天使用 Bouncer 的技術(shù)信息,請查看 the extensive documentation 或者在 The Laravel Podcast 聽我和馬特?斯托弗討論。
什么是 Bouncer?#
在開始我的個人旅程之前,這里先簡要介紹一下 Bouncer 是什么,以及它如何融入更大的 Laravel 生態(tài)系統(tǒng)。
Bouncer 是一個開源包,用于動態(tài)管理數(shù)據(jù)庫中的角色和權(quán)限,與 Laravel 的 Gate 完全集成。
在不深入細節(jié)的情況下,以下是其一些主要功能的簡短列表:
-
Simple abilities:
Bouncer::allow($user)->to('access-dashboard');
登錄后復(fù)制 -
Model abilities:
Bouncer::allow($user)->to('view', Invoice::class); Bouncer::allow($user)->to('delete', $invoice);
登錄后復(fù)制 -
Flexible roles:
Bouncer::allow('admin')->everything(); Bouncer::assign('admin')->to($user);
登錄后復(fù)制 -
Forbidding abilities:
Bouncer::allow($user)->to('view', Invoice::class); Bouncer::forbid($user)->to('view', $confidentialInvoice);
登錄后復(fù)制 -
Powerful ownership:
Bouncer::allow($user)->toOwn(Post::class);
登錄后復(fù)制 -
Straighforward multi-tenancy:
Bouncer::scope()->to($tenantId);
登錄后復(fù)制 -
Built-in caching
Bouncer::cache();
登錄后復(fù)制
… 還有