“This is the 10th day of my participation in the Gwen Challenge in November. Check out the details: The Last Gwen Challenge in 2021.”
There is no high or low level of martial arts in the world, only the strong and weak of martial arts.
The Laravel Artisan command isan Eloquent example of how to use the Laravel Artisan command.
Artisan command
Learn to debug projects using Artisan
Artisan means Artisan, a very useful tool for development.
The postman request interface test is one idea, but it is time-consuming.
We can create the test tool file using the artisan command
php artisan make:command TestPhp
Copy the code
Executing the above command automatically generates the following files in the project (the non-core code already has three vertical ones). Omit), which we can do in the handle() method
<? php namespace App\Console\Commands; use Illuminate\Console\Command; Class TestPhp extends Command {// Change your name to 'TestPhp:Tool'; Public function handle() {}Copy the code
We can easily test through the following command
php artisan TestPhp:Tool
Copy the code
Use Artisan in the code
Not only can the Artisan command be started on the command line, but it can also be started in code with parameters, using the Artisan::call() method:
Route::get('/foo', function () {
$exitCode = Artisan::call('sms:send', [
'user' => 1, '--queue' => 'default'
]);
//
});
Copy the code
Artisan command parameters
When creating the Artisan command, you can ask for input by: $this-> confirm(), $this-> anticipate(), $this->choice().
If ($this->confirm(' do you want to continue? $name = $this->anticipate(' Who are you? ', [' Xiao Ming ', 'Xiao Hua ']); $name = $this->choice(' Who are you? ', [' xiao Ming ', 'Xiao Hua '], $defaultIndex);Copy the code
Maintenance mode
If we want to enable maintenance mode on the site, execute the following Artisan command:
php artisan down
Copy the code
People will then see the default 503 page.
In Laravel 8, we can also provide the following logos:
The user will redirect the path address of the prerendered maintenance mode view page to bypass the maintenance mode of the secret key maintenance mode to return the state of the page every X seconds
php artisan down --redirect="/" --render="errors::503" --secret="xxxxxxx-xxx-xxx-xxx-xxxxxxxxx" --status=200 --retry=60
Copy the code
Before Laravel 8 there were:
Messages displayed in maintenance mode are reloaded every X seconds to allow access to the IP address of the page
PHP artisan down --message=" System update, please access later "-- Retry =60 --allow=127.0.0.1Copy the code
When we are finished with the maintenance work, just run the following command and the site will be accessible.
php artisan up
Copy the code
Artisan Command line help
To see options for the Artisan command, run the Artisan command with the –help identifier, such as PHP Artisan make:model –help
Then we can see the hint:
Options: -a, --all generates migration classes for the model, populates classes, Factory and resource classes -c, --controller creates a new controller for the model -f, -- Factory creates a new factory class for the model --force Creates class -m when the model already exists, --migration creates a new migration class for the model -s, --seed creates a new fill file for the model -p, --pivot identifies whether the generated model is a custom intermediate table model -r, --resource indicates whether the generated controller is a resource controller. -- API Indicates whether the generated controller is an API controller. -- use the ANSI version shows application version - ANSI output - no - ANSI disable ANSI output - n, - no - interaction don't ask any interactive problem - env [= env] the command is run configuration environment - v | vv | VVV, -v indicates the normal output. -vv indicates the detailed output. -vvv indicates that debugging information is displayedCopy the code
Check out Laravel’s version
The following command line allows you to view and confirm the version of Lavavel used for our application
php artisan --version
Copy the code
Last but not least
Technical group please come here. Or add my wechat account wangzhongyang0601 to learn together.
Thank you for your likes, comments and followings. Thank you for your support. Thank you.