1

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

jigsaw075
  • 155
  • 2
  • 16
  • You should probably add it to your deploy script rather than adding it to an endpoint (why on earth would you do that?) – HTMHell Dec 19 '20 at 12:10

2 Answers2

4

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');
}
Reza sh
  • 787
  • 10
  • 20
1

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

brombeer
  • 8,716
  • 5
  • 21
  • 27