承接 luilliarcec/laravel-user-commands 相关项目开发

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

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

luilliarcec/laravel-user-commands

Composer 安装命令:

composer require luilliarcec/laravel-user-commands

包简介

Laravel User Commands is a package that provides the necessary commands for user manipulation from the console.

README 文档

README

run-tests Latest Version on Packagist Quality Score Total Downloads GitHub license

If like me, you have ever considered having commands to manipulate users within your application, this package will help you.

Installation

You can install the package via composer:

composer require luilliarcec/laravel-user-commands

Now publish the configuration file into your app's config directory, by running the following command:

php artisan vendor:publish --provider="Luilliarcec\UserCommands\UserCommandsServiceProvider"

That is all. 😀

Usage

The package has 4 basic commands

Commands Description
user:create Create a new user in your app
user:reset-password Restore a user's password
user:delete Delete a user
user:restore Restore a user

Create Users

php artisan user:create
Fields

All the fields defined in your fillable property of your model will be used when executing the command. If you want to add more fields you can do it from your config file (your file takes precedence over your model, so if you define the fields in your config file the fields of your fillable property will be ignored)

Rules

Whether you have fields defined in your model or in the configuration file, the filled rule will be dynamically applied to those fields. If you want to add custom rules you can do it from the rules key from your configuration file, these will be merged in such a way that those fields that have not been given a custom rule will use the filled rule by default.

After all, you are free to extend the command and configure it to your liking.

php artisan user:create -a username:larcec -a "other_field:Value of field"

or

php artisan user:create --attributes=username:larcec --attributes="other_field:Value of field"

If you want to mark the user's email as verified you can pass the argument --verified Ex.:

php artisan user:create --verified

If your model uses roles and permissions, you must configure the model of the roles and permissions and the name of the relationships in the configuration file.

You can then pass the permissions or roles as arguments.

php artisan user:create -p "user-create" -p "user-edit"

It should be noted that the roles and permissions
must already exist in your database and will be searched by the name field

Once the user has been created, the notification that it has been created will be sent if it implements the MustVerifyEmail interface and if the verification.verify route name exists

If you want to apply your own logic or just save default data for all users, you can extend the command and apply your necessary logic, or copy the prepareForSave method and add your necessary data. Ex.:

<?php

namespace App\Commands;

use Luilliarcec\UserCommands\Commands\CreateNewUserCommand as CreateNewUserCommandBase;

class CreateNewUserCommand extends CreateNewUserCommandBase
{
    protected function prepareForSave(): array
    {
        return $this->merge([
            'password' => Hash::make($this->data['password']),
            'username' => Username::make($this->data['name']),
        ]);
    }
}

$this->data will contain the data of the user that was asked, if you want to access your data that you entered with the --attribute flag you can do it by calling the attributes function which will return a key => value array with your data.

Reset Password User

The command to reset password user receives the value parameter as required. It will be searched by email and if it is not found it will be searched by id

php artisan user:reset-password luis@email.com

However if you want to search for a specific field you can pass it after the value

php artisan user:reset-password larcec -f username

or

php artisan user:reset-password larcec --field username

After executing the command it will ask you to enter a new password and confirm it

Delete Users

In the same way as the command to reset password user, the user is searched by email or id or by specifying a specific field.

php artisan user:delete luis@email.com

or

php artisan user:delete larcec --field username

If your model uses logical elimination, this is executed by default, however if you want to eliminate completely you can pass the --force argument

php artisan user:delete larcec --field username --force

Restore Users

In the same way as the command to reset password user, the user is searched by email or id or by specifying a specific field.

php artisan user:restore luis@email.com

or

php artisan user:restore larcec --field username

Note that this command will only run if your model uses SoftDelete trait

Users With Roles and Permissions

If you want to add roles and permissions to your users, don't forget to configure the relationship name in your configuration file in addition to the role and permission model.

To grant permissions to your user is as easy as:

php artisan user:create -p "user-create" -p "user-edit"

or

php artisan user:create --permissions="user-create" --permissions="user-edit"

If you want to grant all permissions, you can do this:

php artisan user:create -p *

Note that you must send a single permission flag otherwise it will not work.

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email luilliarcec@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

luilliarcec/laravel-user-commands 适用场景与选型建议

luilliarcec/laravel-user-commands 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 317 次下载、GitHub Stars 达 1, 最近一次更新时间为 2020 年 12 月 29 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「user」 「commands」 「laravel」 「luilliarcec」 「laravel-user-commands」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 luilliarcec/laravel-user-commands 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 luilliarcec/laravel-user-commands 我们能提供哪些服务?
定制开发 / 二次开发

基于 luilliarcec/laravel-user-commands 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-12-29