clarkeash/doorman 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

clarkeash/doorman

最新稳定版本:v11.0.0

Composer 安装命令:

composer require clarkeash/doorman

包简介

无描述信息

README 文档

README

GitHub Workflow Status GitHub release (latest SemVer)

Doorman provides a way to limit access to your Laravel applications by using invite codes.

Invite Codes:

  • Can be tied to a specific email address.
  • Can be available to anyone (great for sharing on social media).
  • Can have a limited number of uses or unlimited.
  • Can have an expiry date, or never expire.

Laravel Support

Laravel Doorman
5.x 3.x
6.x 4.x
7.x 5.x
8.x 6.x
9.x 7.x
10.x 8.x
11.x 9.x
12.x 10.x

Installation

You can pull in the package using composer:

composer require "clarkeash/doorman=^10.0"

Next, migrate the database:

php artisan migrate

Usage

Generate Invites

Make a single generic invite code with 1 redemption, and no expiry.

Doorman::generate()->make();

Make 5 generic invite codes with 1 redemption each, and no expiry.

Doorman::generate()->times(5)->make();

Make an invite with 10 redemptions and no expiry.

Doorman::generate()->uses(10)->make();

Make an invite with unlimited redemptions and no expiry.

Doorman::generate()->unlimited()->make();

Make an invite that expires on a specific date.

$date = Carbon::now('UTC')->addDays(7); Doorman::generate()->expiresOn($date)->make();

Make an invite that expires in 14 days.

Doorman::generate()->expiresIn(14)->make();

Make an invite for a specific person.

Doorman::generate()->for('me@ashleyclarke.me')->make();

Alternatively instead of calling make() which will return a collection of invites you can call once() if you only want a single invite generated.

$invite = Doorman::generate()->for('me@ashleyclarke.me')->once(); dd($invite->code);

Redeem Invites

You can redeem an invite by calling the redeem method. Providing the invite code and optionally an email address.

Doorman::redeem('ABCDE'); // or Doorman::redeem('ABCDE', 'me@ashleyclarke.me');

If doorman is able to redeem the invite code it will increment the number of redemptions by 1, otherwise it will throw an exception.

  • InvalidInviteCode is thrown if the code does not exist in the database.
  • ExpiredInviteCode is thrown if an expiry date is set and it is in the past.
  • MaxUsesReached is thrown if the invite code has already been used the maximum number of times.
  • NotYourInviteCode is thrown if the email address for the invite does match the one provided during redemption, or one was not provided during redemption.

All of the above exceptions extend DoormanException so you can catch that exception if your application does not need to do anything specific for the above exceptions.

try { Doorman::redeem(request()->get('code'), request()->get('email')); } catch (DoormanException $e) { return response()->json(['error' => $e->getMessage()], 422); }

Check Invites without redeeming them

You can check an invite by calling the check method. Providing the invite code and optionally an email address. (It has the same signature as the redeem method except it will return true or false instead of throwing an exception.

Doorman::check('ABCDE'); // or Doorman::check('ABCDE', 'me@ashleyclarke.me');

Change Error Messages (and translation support)

In order to change the error message returned from doorman, we need to publish the language files like so:

php artisan vendor:publish --tag=doorman-translations

The language files will then be in /resources/lang/vendor/doorman/en where you can edit the messages.php file, and these messages will be used by doorman. You can create support for other languages by creating extra folders with a messages.php file in the /resources/lang/vendor/doorman directory such as de where you could place your German translations. Read the localisation docs for more info.

Validation

If you would perfer to validate an invite code before you attempt to redeem it or you are using Form Requests then you can validate it like so:

public function store(Request $request) { $this->validate($request, [ 'email' => 'required|email|unique:users', 'code' => ['required', new DoormanRule($request->get('email'))], ]); // Add the user to the database. }

You should pass the email address into the constructor to validate the code against that email. If you know the code can be used with any email, then you can leave the parameter empty.

Config - change table name

First publish the package configuration:

php artisan vendor:publish --tag=doorman-config

In config/doorman.php you will see:

return [ 'invite_table_name' => 'invites', ];

If you change the table name and then run your migrations Doorman will then use the new table name.

Console

Cleanup

To remove used and expired invites you can use the cleanup command:

php artisan doorman:cleanup

Create a new invite

You can create a new invite from the command line using the make command:

php artisan doorman:make php artisan doorman:make --uses=5 --expiry=2025-12-31 --email=me@ashleyclarke.me php artisan doorman:make --unlimited

统计信息

  • 总下载量: 122.34k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1046
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1043
  • Watchers: 15
  • Forks: 45
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固