Español →

Oliver Servín

Weekly auto-reset a Laravel demo app

I have worked on a client's work where I needed to present a public demo of the work in progress App, but wanted to reset the demo after a week by restoring the database to its clean state.

I did it with a simply scheduled task in the schedule method of my application's App\Console\Kernel class.

1namespace App\Console;
2 
3use Illuminate\Console\Scheduling\Schedule;
4use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
5 
6class Kernel extends ConsoleKernel
7{
8 /**
9 * The Artisan commands provided by your application.
10 *
11 * @var array
12 */
13 protected $commands = [
14 //
15 ];
16 
17 /**
18 * Define the application's command schedule.
19 *
20 * @param \Illuminate\Console\Scheduling\Schedule $schedule
21 * @return void
22 */
23 protected function schedule(Schedule $schedule)
24 {
25 $schedule->command('migrate:fresh --force --seed')->weekly();
26 }
27 
28 /**
29 * Register the commands for the application.
30 *
31 * @return void
32 */
33 protected function commands()
34 {
35 $this->load(__DIR__.'/Commands');
36 
37 require base_path('routes/console.php');
38 }
39}

Frequency options are well documented on Laravel docs. You can change it to daily or hourly if you prefer.


Interact with API result values as object properties in Laravel


Get relative path with `route()` in Laravel


Chokidar file watcher to auto-run Pest tests


Chaining "Where" conditions using dynamic methods


Model factories with relationships by using magic methods


Show amount to pay in next billing cycle with Laravel Cashier (Stripe)


Tax calculation with Laravel Cashier for Stripe


How to keep in sync your customers details with Stripe in Laravel


Handle Paddle's marketing consent with Laravel


Custom styling the pay button with Laravel Cashier Paddle


Embed Paddle's checkout widget with Laravel Cashier


Weekly auto-reset a Laravel demo app


Remove the personal_access_tokens table on a fresh Laravel App


Deploy Umami analytics with Launcher


Fix Laravel storage:link using Launcher


Launcher: first impressions


Integrating Tiptap in a Laravel-Livewire project


How to run a Ghost blog on Laravel Forge