Check out Checkmango, the full-stack A/B testing platform.

Building The Laravel Artisan Cheatsheet

Today I released the Laravel Artisan Cheatsheet, a bookmarkable and shareable resource for all Laravel's default artisan commands. The source code for this resource is available on GitHub.

In the past I've tweeted several tips for artisan and the many unknown features and secrets it holds. I've had the idea to create this resource for a while and last night I finally made the time turn it into something I can share.

After make some last-minute adjustments, I finally deployed it. This evening, I've switched the project to use Nuxt.js. This brings a couple of benefits:

  • Generated output - Google loves this!
  • Work on additional features such as; keyboard shortcuts, multiple versions and synopsis tooltips.
  • Easier for other people to contribute.
  • The core
  • The core of the resource is a JSON file that holds all of the data needed to generate the command output. To generate this file I used Tinkerwell and this snippet:
$commands = Artisan::all();

$output = collect($commands)->sortBy(function ($command) {
  return $command->getName();
})->map(function ($command) {
  return [
    'name' => $command->getName(),
    'description' => $command->getDescription(),
    'synopsis' => $command->getSynopsis(),
    'definition' => $command->getDefinition(),
    'aliases' => $command->getAliases(),
    'arguments' => collect($command->getDefinition()->getArguments())->map(function ($argument) {
      return [
        'name' => $argument->getName(),
        'description' => $argument->getDescription(),
        'default' => $argument->getDefault(),
        'required' => $argument->isRequired(),
      ];
    })->values()->all(),
    'options' => collect($command->getDefinition()->getOptions())->map(function ($option) {
      return [
        'name' => $option->getName(),
        'description' => $option->getDescription(),
        'value_required' => $option->isValueRequired(),
        'value_optional' => $option->isValueOptional(),
      ];
    })->values()->all(),
  ];
})->values()->toJson();

Not all of this data is currently used, but the resulting JSON file should contain enough information to future proof the resource.

Anyway, let me know what you think and if you have some ideas, I'd love to see a PR!