Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
`artisan make:?` command would auto-open new file (Controller/Model/etc) in editor.
<?php
namespace App\Events;
class ClassWasGenerated
{
public $path;
public function __construct($path)
{
$this->path = $path;
}
}
<?php
namespace App\Providers;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
class EventServiceProvider extends ServiceProvider
{
protected $listen = [
// truncated for brevity
// Connect the listener to the event.
'App\Events\ClassWasGenerated' => [
'App\Listeners\OpenInSublime',
],
];
// truncated for brevity
}
<?php
namespace Illuminate\Console;
use Illuminate\Support\Str;
use App\Events\ClassWasGenerated;
use Illuminate\Filesystem\Filesystem;
use Symfony\Component\Console\Input\InputArgument;
abstract class GeneratorCommand extends Command
{
// removed because not important to point of Gist
public function handle()
{
// removed because not important to point of Gist
$this->files->put($path, $this->buildClass($name));
// only new line of code in this class (as well as "use")
event(new ClassWasGenerated($path));
// removed because not important to point of Gist
}
<?php
namespace App\Listeners;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
class OpenInSublime
{
public function handle($event)
{
// might be `subl` for some people. But this class would be entirely opt-in and fully customizable.
exec('sublime -a ' . $event->path);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment