1. Go to this page and download the library: Download wnx/laravel-backup-restore library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
wnx / laravel-backup-restore example snippets
return [
/**
* Health checks are run after a given backup has been restored.
* With health checks, you can make sure that the restored database contains the data you expect.
* By default, we check if the restored database contains any tables.
*
* You can add your own health checks by adding a class that extends the HealthCheck class.
* The restore command will fail, if any health checks fail.
*/
'health-checks' => [
\Wnx\LaravelBackupRestore\HealthChecks\Checks\DatabaseHasTables::class,
],
];
namespace App\HealthChecks;
use Wnx\LaravelBackupRestore\PendingRestore;
use Wnx\LaravelBackupRestore\HealthChecks\HealthCheck;
class MyCustomHealthCheck extends HealthCheck
{
public function run(PendingRestore $pendingRestore): Result
{
$result = Result::make($this);
// We assume that your app generates sales every day.
// This check ensures that the database contains sales from yesterday.
$newSales = \App\Models\Sale::query()
->whereBetween('created_at', [
now()->subDay()->startOfDay(),
now()->subDay()->endOfDay()
])
->exists();
// If no sales were created yesterday, we consider the restore as failed.
if ($newSales === false) {
return $result->failed('Database contains no sales from yesterday.');
}
return $result->ok();
}
}