Home > PHP Framework > Laravel > Let's talk about how laravel uses commands to execute scripts

Let's talk about how laravel uses commands to execute scripts

藏色散人
Release: 2021-11-23 15:43:44
forward
2889 people have browsed it

The following tutorial column of Laravel will introduce how to use laravel commands to execute scripts. I hope it will be helpful to everyone!

laravel Use the command to execute the script

1. Generate the console file

 php artisan make:console TestConsole --command=laravel:test
Copy after login

2. Edit the business logic in the handle method

<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class HelloLaravelAcademy extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = &#39;laravel:test {name?}&#39;;
    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = &#39;Command description&#39;;
    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }
    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        echo $this->argument("name").PHP_EOL;
        echo 123;
    }
}
Copy after login

$signature indicates whether to receive parameters, ? indicates that it is not required. arguement receives parameters

execute

 php artisan laravel:test
 
 php artisan laravel:test xiaoming
Copy after login

[Related recommendations: The latest five Laravel video tutorials

The above is the detailed content of Let's talk about how laravel uses commands to execute scripts. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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 Issues
Composer cannot install laravel
From 1970-01-01 08:00:00
0
0
0
Laravel Space/laravel-backup cannot be installed
From 1970-01-01 08:00:00
0
0
0
Laravel 5.1 Login laravel comes with it No more
From 1970-01-01 08:00:00
0
0
0
Why thinkphp has better performance than laravel?
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template