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…

 

Ajith Jojo Joseph

Hire Me for Freelancing $30/Hour ,
Contact via email : [email protected]

Share with your friends:

Comments are closed.

How To Generate A PDF from HTML in Laravel 11

Hello , I was trying to generate a PDF payment receipt for my SAAS application and when i search for […]

June 22, 2024

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

Digital Marketing Toolkit

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

Get Free Access Now