laravel - How to display a message in console using a seeder class in Laravel 5.8?
问题描述
To display an error while using Laravel Artisan the official Laravel 5.8 documentation says:
$this->error('Something went wrong!');
But what's the context of $this
?
Following is the contents of the seeder class file:
use Illuminate\Database\Seeder;
class PopulateMyTable extends Seeder
{
public function run()
{
$this->info("Console should show this message");
}
}
解决方案
您可以通过$this->command->method()
.
$this
这个Seeder实例
在哪里,command
这个种子控制台Command实例在哪里,
并且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');
}
}
推荐阅读
- javascript - 遍历两个数组,找出匹配的值
- python - 向 lambda 函数添加多个表达式,以获取 if/else 输出
- javascript - 如何以编程方式获取 YouTube 网址?
- python - 具有多处理功能的 Write():内置锁定以防止输出乱码?
- java - Java - Mockito - 如何在测试中将依赖注入抽象
- apache-spark - Spark SQL:从另一个数据帧中减去一个数据帧的相应行
- python-3.x - 写入 STATIC_ROOT 时,Django sqlite“数据库已锁定”
- c# - 粒子系统仅在 GetButton() 的开始和结束时播放
- jquery - 找到完全匹配文本的 CSS 选择器
- c# - Winforms - C# 任务栏进度指示器 (Windows 10)