承接 gtcrais/laravel-persona 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

gtcrais/laravel-persona

最新稳定版本:v1.0.0

Composer 安装命令:

composer require gtcrais/laravel-persona

包简介

README 文档

README

This is NOT a first-party package. This package adds Visitor and Persona concepts to your Laravel application.

Requirements: Tested on Laravel 12. It should work on lower versions as well.

Note: Docs could use more information, but I made this package mainly for myself. If you happen to use it, hit me up, and I'll update the docs with better explanations.

Visitor: Non-registered user which still needs to be tracked and stored into the database. This is achieved using UUID stored in a cookie.

Persona: Umbrella model for Users and Visitors. When calling request()->persona(), it will return currently logged in User if it exists. If not, it will return currently tracked Visitor if it exists. If not, it will return null.

Installation:

  • Run composer require gtcrais/laravel-persona
  • Run php artisan laravel-persona:install
  • Add ... implements GTCrais\LaravelPersona\Models\Contracts\Persona Contract to your User model
  • Add use GTCrais\LaravelPersona\Models\Concerns\UserPersona Concern to your User model
  • Migrate the database
  • Register middleware:
use App\Http\Middleware\AuthPersona;
use App\Http\Middleware\EnsurePersonaExists;
use App\Http\Middleware\ResolvePersona;

$middleware->appendToGroup('web', [ResolvePersona::class]);
$middleware->appendToGroup('api', [ResolvePersona::class]);
$middleware->alias(['ensurePersonaExists' => EnsurePersonaExists::class]);
$middleware->alias(['authPersona' => AuthPersona::class]);
  • Upon successful login:
use App\Http\Middleware\Concerns\InteractsWithVisitor;

...

if ($visitor = auth()->guard('web')->user()->visitor) {
    $this->setVisitorUuidCookie($visitor->uuid);
    $this->injectVisitorData(request(), $visitor);
}
  • Upon successful registration:
use App\Http\Middleware\Concerns\InteractsWithVisitor;

...

$visitor = $this->optionallyCreateVisitor();

$this->associateVisitorWithUser($visitor, $user);
$this->injectVisitorData(request(), $visitor);

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-05-23