How to run Laravel php artisan migrate in a controller

After deploying your software updates you may need to run the  “php artisan migrate” command. that you can do it simply if you are in a development server or by using a terminal.

but in some cases, you don’t have a terminal to do it. so then what do you do?  if I were in your position I will make a function to do it. when I browse a URL it will get executed.

so first we have to create a controller and create a function in it

public function runupdate()
{     
    Artisan::call('migrate');      
}

Yes you just need to call this Artisan::call('migrate');  Function

but you have to add  use Artisan;   namespace in the top



 

and the final code will look like this 

use Artisan;

class Yourcontrollername extends Controller
{
   public function runupdate()
    {     
       Artisan::call('migrate');      
    }
}

 

Hope this helps .. See you in the next one…

 

Post Your Questions on our forum

Post a question on Forum

Ajith Jojo Joseph

Self taught, dedicated young entrepreneur with many licensed products under his sleeve. Passionate about technology, business and excellence in general.

Share with your friends:

Comments are closed.

How to create Laravel Flash Messages

Laravel flash messages are a convenient way to display one-time notifications to the user after a form submission or other […]

December 22, 2022

How to make Custom Artisan Command in Laravel

Custom Artisan commands are a useful feature of Laravel that allow you to define your own command-line commands for tasks […]

December 22, 2022

Tips for Laravel migrations

Laravel migrations are a powerful tool for managing and modifying your database schema in a structured and organized way. Here […]

December 22, 2022

Tricks and tips for Laravel blade templating

Welcome to our blog about tricks and tips for Laravel blade templating! Blade is the default templating engine for Laravel, […]

December 22, 2022

Digital Marketing Toolkit

Get Free Access to Digital Marketing Toolkit. You can use all our tools without any limits

Get Free Access Now