stackprogramer's avatar

How restore db in laravel when i remove db completely first

I need a chunk restore method, because db and files are too big, files extracts successfully. but for db after ajax request time 2 and 3 we had error in provider....middlewares.... I added exception for restore method but it wasn't fixed.....

Error:

[2025-12-18 14:53:53] local.ERROR: Attempt to read property "headers" on null {"userId":1,"exception":"[object] (ErrorException(code: 0): Attempt to read property \"headers\" on null at /home/adam/public_html/local/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php:191)
[stacktrace]

Solutio that i tested but not solved it.

<?php
namespace App\Http\Middleware;
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;
class VerifyCsrfToken extends Middleware
{
  /**
   * Indicates whether the XSRF-TOKEN cookie should be set on the response.
   *
   * @var bool
   */
  protected $addHttpCookie = true;
  /**
   * The URIs that should be excluded from CSRF verification.
   *
   * @var array
   */
  protected $except = [
    //
    '/restore', // or whatever your actual route path is
    'restore',   // Matches your /restore/ path
    'restore/*', // Matches any sub-paths if necessary
  ];
}

Restore method

0 likes
8 replies
stackprogramer's avatar

Thanks, But I don't access shell exec on CPanel Host providers. I want to use a way without shell executing. This is important for us.

1 like
martinbean's avatar

Thanks, But I don't access shell exec on CPanel Host providers. I want to use a way without shell executing. This is important for us.

@stackprogramer Then restore through a GUI such as TablePlus that will let you restore from a file, and will it far more reliably than through a PHP script that is definitely going to have memory and timeout limits if you’re on a shared host.

Why are you removing and restoring databases on your host in the first place?

stackprogramer's avatar

@martinbean

Hi, I work on a custom CMS based on Laravel. I want to develop a package restore (alike duplicator Wordpress) for Laravel. Our restore package is GUI and easy to use for end users. Really my goal is reverse engineering duplicator wp for our custom CMS. In duplicator it had a chunk to chunk importing (files and database).

@tray2

Thanks, Rather we need create our custom package for Custom CMS. I checked it before. https://packagist.org/packages/spatie/laravel-backup

Snapey's avatar
Snapey
Best Answer
Level 122

make sure you are not trying to restore any tables that are in use, like users, sessions or jobs.

1 like
stackprogramer's avatar

Thanks, I am developing a custom CMS on based Laravel. I need a tool like duplicator Wordpress like it. I want to users can backup and restore all files and db at a glance. I can't ignore some table in this situation.

stackprogramer's avatar

Finally I defined some critical tables like users,sessions and... and i restore them(critical tables) in final step. This advice was helpful for me. Thanks very much.

Please or to participate in this conversation.