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");
}
}
There are two ways by the help of which we can run a specific seeder file when we need. By using DatabaseSeeder. php file. By using –class flag in artisan command.
Seeder or called Database Seeder is a feature of Laravel Php framework, which is used to auto generate data when an initial version is instantiated. We use a seeder to test our laravel project quickly and efficiently.
You can do it by $this->command->method()
.
Where $this
is this Seeder instance,
command
is this seeder console Command instance,
and method()
could be any of the command available output methods.
<?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');
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With