dev-master
9999999-dev https://github.com/jsiebach/commanderA Laravel Backpack-driven interface for executing artisan commands
MIT
The Requires
by Jeff Siebach
laravel artisan laravel backpack
Wallogit.com
2017 © Pedro Peláez
A Laravel Backpack-driven interface for executing artisan commands
Backpack Commander is a simple CRUD interface for running Artisan commands in Backpack for Laravel. The main benefit is to quickly allow non-developers to run Artisan commands without needing command line access, and to easily configure the arguments and options for the command line using Backpack field definitions., (*1)
, (*2)
Install Backpack for Laravel, (*3)
Install Backpack Commander, (*4)
composer require jsiebach/commander, (*5)
php artisan vendor:publish --provider="JSiebach\Commander\CommanderServiceProvider" --tag="config", (*6)
php artisan vendor:publish --provider="JSiebach\Commander\CommanderServiceProvider" --tag="migrations", (*7)
route: Edit the route for the commander interface. Defaults to /admin/commander/command., (*8)
allow_creation_and_deletion: Determine whether new commands can be added or deleted. It is recommended to keep this option false in a production environment and add new commands directly in the database., (*9)
Run php artisan migrate, (*10)
Add your commands interface link to the sidebar (Optional), (*11)
<li><a href="{{ backpack_url('commander')."/command" }}"><i class="fa fa-bullhorn"></i> <span>Commands</span></a></li>, (*12)
You can now add new commands to your commander_commands table. The fields are:, (*13)
command: The artisan command (ie. inspire - whatever you would fill in for php artisan XXXXX), (*14)
descriptive_name: A name to show users for the command. Will default to the artisan command name, (*15)
The CRUD interface will also show a column with the description property of the command., (*16)
To define a command, add a function to the command called getCommanderFields(), which should return an array of Backpack field definitions., (*17)
For simple commands like inspire, you can leave off the getCommanderFields() function entirely., (*18)
For commands that take arguments and options, you should return the Backpack field configuration in the getCommanderFields() function on the command. For example:, (*19)
<?php
namespace App\Console\Commands;
use App\User;
use Illuminate\Console\Command;
use JSiebach\Commander\CommandableInterface;
class RunNewUsersReport extends Command implements CommandableInterface
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'reports:run-new-users-report {--startdate=} {--include-admins} {--delivery-email=}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Run a report listing the newest users';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
// You can use the arguments of the artisan command as normal:
$this->comment('The email address to send the report to is '.$this->option('email'));
$this->comment('The option \'include-admins\' is '.(((boolean) $this->option('include-admins')) ? "true" : "false"));
$this->comment('The start date for the report is '.$this->option('start-date'));
}
/**
* @return array
*/
public function getCommanderFields() {
return [
[
'name' => '--startdate',
'type' => 'date_picker',
'label' => 'Start Date'
],
[
'name' => '--include-admins',
'type' => 'checkbox',
'label' => 'Include Admin Users'
],
[
'name' => '--delivery-email',
'type' => 'select2_from_array',
'options' => User::all()->pluck('name', 'email'),
'label' => 'Report Recipient'
]
];
}
}
In the commands CRUD interface, click the Run button to run a command. You will see a form generated by the fields defined on the command., (*20)
Fill out the fields and click Run. The output of the command will be printed in the resulting view., (*21)
If you want to run a command on the queue, add the field --queue_command. If you want this to be an option, you can use a check box. If you want it to be automatic, use a hidden field with value 1., (*22)
You can specify the name of the queue with the --queue_name option. Defaults to default, (*23)
$commandable = true on commands that should be included)Please feel free to submit issues or pull requests on Github., (*24)
MIT, (*25)
Backpack for Laravel, (*26)
A Laravel Backpack-driven interface for executing artisan commands
MIT
laravel artisan laravel backpack