1

I have one website url which takes a long time to run.

It is added in route but want to run it via terminal. This route call a moethod from my controller. as routes does not has php extension so this route will not able to run via php command.

How can I run a laravel route via terminal/CLI.

route :

 Route::get('backup', array(
            'uses' => 'DocBackupsController@backup'
        ));

what will be my terminal command for it.

I have got solution for it 1) create laravel command using following command

php artisan command:make BackupThemeCommand

2) Above command will create app/commands/BackupThemeCommand.php file with few contents. update following content to this file, set name using colon to a artisan command.

protected $name = 'backup:theme';

3) Add following content to a fire method of above created file and save the file.

$obj = new DocBackupsController();
                $obj->backup();

4) Add following line to app/start/artisan.php

Artisan::add(new BackupThemeCommand);

5) call above command using terminal

sudo php artisan backup:theme

This will let you run a code from terminal..

vishal-mote
  • 362
  • 2
  • 6
  • 22

1 Answers1

1

Instantiate the DocBackupsController object and call the backup() method from within some cli script. You are using dependency injection yeah?

Mariusz Jamro
  • 30,615
  • 24
  • 120
  • 162