Home> PHP Framework> Laravel> body text

Laravel - Artisan Console

PHPz
Release: 2024-08-27 13:12:12
Original
320 people have browsed it

Laravel framework provides three primary tools for interaction through command-line namely:Artisan, TickerandREPL. This chapter explains about Artisan in detail.

Introduction to Artisan

Artisan is the command line interface frequently used in Laravel and it includes a set of helpful commands for developing a web application.

Example

Here is a list of few commands in Artisan along with their respective functionalities −

To start Laravel project

php artisan serve
Copy after login

To enable caching mechanism

php artisan route:cache
Copy after login

To view the list of available commands supported by Artisan

php artisan list
Copy after login

To view help about any command and view the available options and arguments

php artisan help serve
Copy after login

The following screenshot shows the output of the commands given above −

Artisan Help Serve

Writing Commands

In addition to the commands listed in Artisan, a user can also create a custom command which can be used in the web application. Please note that commands are stored inapp/console/commands directory.

The default command for creating user defined command is shown below −

php artisan make:console 
Copy after login

Once you type the above given command, you can see the output as shown in the screenshot given below −

Laravel - Artisan Console

The file created forDefaultCommandis named asDefaultCommand.phpand is shown below −


        
Copy after login

This file includes the signature and description for the command that user defined. The public function namedhandleexecutes the functionalities when the command is executed. These commands are registered in the fileKernel.phpin the same directory.

You can also create the schedule of tasks for the user defined command as shown in the following code −

command('inspire') // ->hourly(); } }
Copy after login

Note that the schedule of tasks for the given command is defined in the function namedschedule, which includes a parameter for scheduling the tasks which takeshourlyparameter.

The commands are registered in the array of commands, which includes the path and name of the commands.

Once the command is registered, it is listed in Artisan commands. The values included in the signature and description section will be displayed when you call for the help attribute of the specified command.

Let us see how to view the attributes of our commandDefaultCommand. You should use the command as shown below −

php artisan help DefaultCommand
Copy after login

The above is the detailed content of Laravel - Artisan Console. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!