Skip to content

Instantly share code, notes, and snippets.

@djaiss
Created August 20, 2020 21:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djaiss/a2f1702a100da3febe60434b25e73df4 to your computer and use it in GitHub Desktop.
Save djaiss/a2f1702a100da3febe60434b25e73df4 to your computer and use it in GitHub Desktop.
<?php
namespace App\Console\Commands;
class SetupDummyAccount extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'setup:dummyaccount';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Prepare an account with fake data so users can play with it';
/**
* Create a new command instance.
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$this->start();
$this->wipeAndMigrateDB();
$this->createFirstUser();
$this->assignAccountantRole();
$this->createEmployeeStatuses();
$this->createPositions();
$this->createTeams();
$this->createEmployees();
$this->addSkills();
$this->addWorkFromHomeEntries();
$this->addWorklogEntriesAndMorale();
$this->createQuestions();
$this->addAnswers();
$this->addExpenses();
$this->stop();
}
private function start(): void
{
if (! $this->confirm('Are you sure you want to proceed? This will delete ALL data in your environment.')) {
return;
}
$this->line('This process will take a few minutes to complete. Be patient and read a book in the meantime.');
$this->faker = Faker::create();
}
private function wipeAndMigrateDB(): void
{
$this->artisan('☐ Migration of the database', 'migrate:fresh');
$this->artisan('☐ Symlink the storage folder', 'storage:link');
}
private function createFirstUser(): void
{
$this->info('☐ Create first user of the account');
$user = (new CreateAccount)->execute([
'email' => 'admin@admin.com',
'password' => 'admin',
'first_name' => 'Michael',
'last_name' => 'Scott',
]);
$this->company = (new CreateCompany)->execute([
'author_id' => $user->id,
'name' => 'Dunder Mifflin',
]);
// grab the employee that was just created
$this->michael = Employee::first();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment