Laravel 5.3 - Is it possible to run php artisan command by clicking on a link/button

lewis4u

So as the question says...is there a way to run php artisan command in background when user clicks on a link in web browser?

For example i would like to make a button in my app for migrating migration files so when this button is clicked:

<a href="/migrate" class="btn btn-primary">Migrate</a>

i would like to run

php artisan migrate

in background.

Is this somehow possible?

Risan Bagja Pradana

Sure you can! Just simply create a new route within your routes\web.php file. Then you can just simply call Artisan::call() method.

For example, when you visit make-migration route, you want to create a migration file for Invoices table. You can do this like so:

Route::get('make-migration', function () {
    Artisan::call('make:migration', [
        'name' => 'create_invoices_table',
        '--create' => 'invoices',
    ]);

    return 'Create invoices migration table.';
});

Or in your case, if you want to run the migration:

Route::get('migrate', function () {
    Artisan::call('migrate');

    return 'Database migration success.';
});

Read more about running Artisan command programmatically here.

Hope this help!

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Run artisan command in laravel 5

Laravel 5 - how to run a Controller method from an Artisan Command?

Laravel - Unable to run artisan command

Laravel | MySQL error when i run php artisan migrate command

how run laravel php artisan websocket:init command on online server?

Run laravel 5 app without php artisan serve

How to run laravel artisan command on server?

Why the php artisan: schedule run command does not execute the artisan commands?

Laravel 5 - Creating Artisan Command for Packages

Laravel 5 console (artisan) command unit tests

Laravel project gives Undefined property error when run php artisan serve command

Unable to run php artisan migrate in Laravel

php artisan up command not working in laravel?

Laravel: PHP artisan Command Stopped Working

Php Artisan serve command not serving Laravel 5.8

How to run artisan command schedule:run on hosting server? (Laravel)

How to run Laravel artisan command without using command line

how to create command with argument in laravel 5(use phpmd as php artisan phpmd )?

Laravel 5 - Php artisan syntax error

Laravel 5: php artisan migrate:refresh

php artisan migrate not working in docker and laravel 5

Unable to run artisan command via cron [laravel 5.2]

Unable to run a Laravel Artisan command with parameters using Symfony process

error when i run php artisan migrate command on line 51

Error in Laravel Artisan command

How to save/redirect output from Laravel 5 Artisan command?

Laravel 5 - How to create an Artisan command to execute bash script

Laravel 5: How to get config value in artisan console command

PHP Artisan Custom Command