skip to Main Content

I want to create a php file in public directory that runs php artisan migrate:fresh (–seed) command in server. when I upload my project to FTP server I want to open that link (ex: www.project.com/migration.php) and that file should run migration and/or seed files. is it possible
if it is how can I do that?

btw I use Laravel 7.28 version

2

Answers


  1. You can call artisan commands like this in functions or even in routes!

    public function callArtisanCommands()
    {
        Artisan::call('cache:clear');
        Artisan::call('view:clear');
        Artisan::call('route:clear');
        Artisan::call('migrate:fresh');
    }
    
    Login or Signup to reply.
  2. Create a route that calls the Artisan command:

    Route::get('migrate', function () {
        $exitCode = Artisan::call('migrate:fresh --seed --force');
    });
    

    Added the --force parameter because in a production environment migrations need to be confirmed.

    More info on Programmatically Executing Commands

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search