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 get data from a model on all pages in Laravel – Simple Way

Do you know How to get data from a model on all pages in Laravel ? In this blog post, […]

August 5, 2022

How to create a Laravel Collection From JSON

Today i have to create a laravel collection from a JSON object. I search on the internet and I cant […]

August 3, 2022

Laravel Eloquent WhereNull() and whereNotNull() Example

Do you know how to use WhereNull() and whereNotNull() Laravel Eloquent. In this post, I will explain how to use […]

July 28, 2022

Laravel Array to JSON Response From Laravel Controller

Do you know how to make JSON responses from a Laravel array? As a developer someday we all have to […]

July 28, 2022

Digital Marketing Toolkit

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

Get Free Access Now