Start a Project

How to Create Custom Artisan Commands in Bagisto

In this article, we are going to see how to create custom artisan commands in bagisto.

What is Artisan Command?

Artisan is a command line tool in Laravel to interact with the application. Artisan helps in lot way to create application classes, databases, migrations, run server or view application list.

As we know, Laravel provides artisan commands to interact with applications. You really wonder how the artisan command works. You can also create your custom artisan command in Bagisto.

Create Custom Artisan Command in Bagisto

You can create your own custom artisan command, which will execute blocks of code as per requirements. This includes creating caching, running cronjobs, sending mails etc.

Steps to create the command:-

Step 1: Create an artisan command file

Create a New Command directory inside the Console folder of the package, and make a custom command class inside the command folder.

Step 2: Customize the command class file as per your requirement

After creating the command class file at packages\Webkul\Core\Console\Commands\BagistoVersion.php

$signature property of the command class will be the command that you will execute into the terminal.
In our case, set $signature to bagisto:version

Next, set up the $description as per you wish,This will tell you what the command does.

Next, in the handle method which is the code block function executed when the command run, perform whatever action you intend it to perform. In this example, we are displaying the bagisto version.

Step 3: Register Your Command in your Package’s Service-Provider

Register all the custom commands in the register() method of the service provider

Finally, In the terminal, run the command to see the desired result.

The output of the command in the terminal.

 

So, that was much about the article “ How to Create Custom Artisan Commands in Bagisto ”. Also for any queries or doubts reach out to us at support@webkul.com. You can also raise a ticket at our HelpDesk System.

 

Exit mobile version