happydemon/usrlastly
最新稳定版本:0.2
Composer 安装命令:
composer require happydemon/usrlastly
包简介
Keep track of your users' last visit
README 文档
README
This nifty little package makes it easy to store and retrieve a user's 'last seen' status.
It's a light implementation that's easy to extend.
It uses a middleware to check if a user is logged in, if so it will store the user's current visit.
Installation
First add the package to your composer file by runningthis command:
composer require happydemon/usrlastly
This will install the latest version.
Next add the service provider in your app.php config:
'providers' => [ ... 'HappyDemon\UsrLastly\UsrLastlyServiceProvider', ]
Next publish the config file:
php artisan vendor:publish
Now it's time to register LastSeenMiddleware as global middleware in app/Http/Kernel.php:
protected $middleware = [ ... 'HappyDemon\UsrLastly\Middleware\LastSeenMiddleware' ];
Lastly let's move on to your user model, open it and add the required trait:
Above your class reference the trait
use HappyDemon\UsrLastly\LastSeenTrait as LastSeen;
and in your user model add
use LastSeen;
Storages
I've bundled 2 types of storage, this is where the 'last seen status' gets stored.
You can either store this status in your database or with Redis.
Database
To let this package do its work you'll first need to publish and run a database migration
php artisan vendor:publish --provider="HappyDemon\UsrLastly\UsrLastlyServiceProvider" --tag="migrations" php artisan migrate
That should have prepared your database and you should be ready.
Redis
This storage requires even less setup, all you have to do is open up config/userlastly.php and change the storage key to redis
User provider
I'm sure not everybody is using Laravel's built-in Auth to handle user authentication so I've extracted this bit too, at this moment though it's the only auth implemented.
This is something that's used by the package, not something other developers should worry about.
We can do this in 3 steps:
- Create a class that implements
HappyDemon\UsrLastly\Userwith agetUser()method that returns a logged in user or false - Binding that class to laravel's container
- Change
config/userlastly.php'suser_providerkey to name of that binding.
You can check the docs for the worked out example.
Retrieving 'last seen' status
Load your user like you would normally and call lastSeen(), as an example I'll just grab the first user in the database:
$user = User::find(1); dd($user->lastSeen());
That method should return an object with 2 properties:
- date which is a
Carbondate object - request, an array which holds information on where the user was
happydemon/usrlastly 适用场景与选型建议
happydemon/usrlastly 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 220 次下载、GitHub Stars 达 14, 最近一次更新时间为 2015 年 03 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「user」 「laravel」 「last」 「Usr」 「lastly」 「seen」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 happydemon/usrlastly 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 happydemon/usrlastly 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 happydemon/usrlastly 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Simple class to provide title, first name, middle initial and last name from a full name field (or in reverse). Works well for western(ish) names, but has sensible defaults otherwise
A handy WordPress library for building all kinds of paginations.
Add Last Posted User Avatar to DiscussionList
Standalone replacement for php's native get_browser() function
User component for Yii2
Symfony 2 bundle to add quickly last tweets on your website
统计信息
- 总下载量: 220
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 14
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-03-29