Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

officelifehq/officelife

942 stars
1 code files
View officelifehq/officelife on GitHub

app/Console/Commands/Demo/ResetDemo.php

Open in GitHub
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Console\ConfirmableTrait;
 
class ResetDemo extends Command
{
use ConfirmableTrait;
 
protected $signature = 'demo:reset
{--force : Force the operation to run when in production.}';
 
protected $description = 'Reset the demo env';
 
public function handle(): void
{
if (! config('officelife.demo_mode')) {
$this->line('This command is only available in demo mode.');
return;
}
 
if ($this->confirmToProceed()) {
try {
Artisan::call('down');
 
if (Cache::has('databasereset')) {
$sql = Cache::get('databasereset');
} else {
$this->line('Downloading file...');
$file = Http::get('https://github.com/officelifehq/demosql/raw/main/officelife.sql');
$file->throw();
 
$sql = $file->body();
Cache::put('databasereset', $sql, 7200);
}
 
$this->line('Running transaction...');
DB::unprepared($sql);
 
$this->line('Running migration...');
Artisan::call('migrate', ['--force' => true, '--verbose' => true]);
} finally {
Artisan::call('up');
}
 
$this->line('Database cleaned.');
}
}
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.