Download the PHP package luilliarcec/laravel-user-commands without Composer
On this page you can find all versions of the php package luilliarcec/laravel-user-commands. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download luilliarcec/laravel-user-commands
More information about luilliarcec/laravel-user-commands
Files in luilliarcec/laravel-user-commands
Package laravel-user-commands
Short Description Laravel User Commands is a package that provides the necessary commands for user manipulation from the console.
License MIT
Homepage https://github.com/luilliarcec/laravel-user-commands
Informations about the package laravel-user-commands
Laravel User Commands V3
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:
Now publish the configuration file into your app's config directory, by running the following command:
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
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.
or
If you want to mark the user's email as verified you can pass the argument --verified
Ex.:
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.
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.:
$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
However if you want to search for a specific field you can pass it after the value
or
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.
or
If your model uses logical elimination, this is executed by default, however if you want to eliminate completely you can pass the --force argument
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.
or
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:
or
If you want to grant all permissions, you can do this:
Note that you must send a single permission flag otherwise it will not work.
Testing
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 [email protected] instead of using the issue tracker.
Credits
- Luis Andrés Arce C.
- All Contributors
License
The MIT License (MIT). Please see License File for more information.