whilesmart/laravel-user-devices
Composer 安装命令:
composer require whilesmart/laravel-user-devices
包简介
Package for managing user devices across our projects
README 文档
README
This Laravel package provides a complete devices solution ready to be integrated into your application.
Features
- Ready-to-use devices endpoints:
- OpenAPI documentation: Automatically generated documentation using PHP attributes.
- Configuration file: Easily customize settings.
- Laravel agnostic considerations: designed with future framework agnosticism in mind.
Installation
1. Require the package
composer require whilesmart/laravel-user-devices
2. Publish the configuration and migrations:
You do not need to publish the migrations and configurations except if you want to make modifications. You can choose to publish the migrations, routes, controllers separately or all at once.
2.1 Publishing only the routes
Run the command below to publish only the routes.
php artisan vendor:publish --tag=user-devices-routes php artisan migrate
The routes will be available at routes/user-devices.php. You should require this file in your api.php
file.
require 'user-devices.php';
2.2 Publishing only the migrations
+If you would like to make changes to the migration files, run the command below to publish only the migrations.
php artisan vendor:publish --tag=laravel-user-devices-migrations php artisan migrate
The migrations will be available in the database/migrations folder.
2.3 Publish only the controllers
By default the controllers assign the device to the currently logged in user. If you would like to assign the device to
another model, you can publish the controllers and make the necessary changes to the published file.
To publish the controllers, run the command below
php artisan vendor:publish --tag=laravel-user-devices-controllers php artisan migrate
The controllers will be available in the app/Http/Controllers directory.
Finally, change the namespace in the published controllers to your namespace.
Note: Publishing the controllers will also publish the routes. See section 2.1
2.4 Publish the config
To publish the config, run the command below
php artisan vendor:publish --tag=laravel-user-devices-config
The config file will be available in the config/user-devices.php.
The config file has the folowing variables:
register_routes: Defaulttrue. Auto registers the routes. If you do not want to auto-register the routes, set the value to `falseroute_prefix: Defaultapi. Defines the prefix for the auto-registered routes.db_table_name: Defaultdevices. Defines the name of the database table to create.
2.5 Publish OpenAPI Documentations
php artisan vendor:publish --tag=laravel-user-devices-docs
The documentation will be available in the app/Http/Interfaces directory.
2.6 Publish Locals
php artisan vendor:publish --tag=laravel-user-devices-locals
The locales will be available in the resources/lang/<locale>/devices.php.
2.7 Publish everything
To publish the migrations, routes and controllers, you can run the command below
php artisan vendor:publish --tag=laravel-user-devices php artisan migrate
Note: See section 2.1 above to make the routes accessible
3. Model Relationships
We have implemented a Trait HasDevices that handles relationships. If your model has devices, simply use the
HasDevices trait in your model definition.
use Whilesmart\UserDevices\Traits\HasDevices class MyModel { use HasDevices; }
You can call yourModel->devices() to get the list of devices tied to the model
$model = new MyModel(); $model->devices();
The HasDevices trait also has the getDevicesAttribute() method. If you want to append the devices to the model
response, simply add devices to your model's $appends
use Whilesmart\UserDevices\Traits\HasDevices; class MyModel { use HasDevices; protected $appends = ['devices']; }
Usage
After installation, the following API endpoints will be available:
- POST /api/devices: Registers a new device linked to the current logged in user.
- Get /api/devices: Retrieves all devices linked to the current logged in user.
- PUT /api/devices/{id}: Updates the device information.
- DELETE /api/devices/{id}: Deletes a device from the database.
- OpenAPI Documentation: Accessible via a route that your OpenAPI package defines.
Example Registration Request:
{
"token":"unique_token_string",
"name":"Chrome on Windows",
"type":"web",
"identifier":"device_identifier",
"platform":"Windows"
}
whilesmart/laravel-user-devices 适用场景与选型建议
whilesmart/laravel-user-devices 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.28k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 07 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 whilesmart/laravel-user-devices 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 whilesmart/laravel-user-devices 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 1.28k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 11
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-07-25