要在使用 Laravel Artisan 时显示错误,官方 Laravel 5.8 文档说:
$this->error('出了点问题!');
但是上下文是$this什么?
以下是播种机类文件的内容:
use Illuminate\Database\Seeder;
class PopulateMyTable extends Seeder
{
public function run()
{
$this->info("Console should show this message");
}
}
Run Code Online (Sandbox Code Playgroud)
您可以通过$this->command->method().
$this这个Seeder实例在哪里,
command这个 Seeder 控制台命令实例在哪里,
并且method()可以是任何可用的命令输出方法。
<?php
use Illuminate\Database\Seeder;
use App\User;
use Illuminate\Support\Facades\Hash;
class UserSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$message = 'sample ';
$this->command->info($message . 'info');
$this->command->line($message . 'line');
$this->command->comment($message . 'comment');
$this->command->question($message . 'question');
$this->command->error($message . 'error');
$this->command->warn($message . 'warn');
$this->command->alert($message . 'alert');
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1147 次 |
| 最近记录: |