-
How to make command with parameters? class GenerateSubKey extends BaseCommands
{
protected static $aliases = [ '/generate', '/GetKey' ];
protected static $description = 'Send "/generate" or "/GetKey" to get subscription key';
public function handle()
{
if ($this->getClient()->client_id == config('settings.admin_id')) {
// Generate a subscription key
$generated_key = Str::uuid()->toString();
$days=30;
$expire = Carbon::now()->addDays($days);
// save it
$subscription = $this->CreateKey($generated_key,$expire);
if ($subscription) {
// send it to the admin
$this->sendMessage(["text" => $generated_key]);
} else {
$this->sendMessage(["text" => 'Something Wrong!.']);
}
}
}
protected function CreateKey($generated_key,$expire){
$subscription = new Subscription();
$subscription->key = $generated_key;
$subscription->expire_at = $expire;
$result = $subscription->save();
return $result;
}
} I want to make $days parmater in command that i can type : |
Beta Was this translation helpful? Give feedback.
Answered by
punyflash
Mar 6, 2023
Replies: 1 comment 2 replies
-
You can create a method to extract arguments from your command: protected function arguments()
{
$command = array_filter(explode(' ', $this->update->message()->text));
array_shift($command);
return array_values($command);
} This is the simplest way, but If you need more complex arguments, you may add a custom algorithm using regex or other. Then just use this method (for example, if command was [$days] = $this->arguments();
// $days == 5 |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
mko543
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can create a method to extract arguments from your command:
This is the simplest way, but If you need more complex arguments, you may add a custom algorithm using regex or other.
Then just use this method (for example, if command was
/generate 5
):