Skip to content

Instantly share code, notes, and snippets.

@nasrulhazim
Last active November 21, 2016 13:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nasrulhazim/3eb40db9f2c538c68d4d98b87b6eb7e6 to your computer and use it in GitHub Desktop.
Save nasrulhazim/3eb40db9f2c538c68d4d98b87b6eb7e6 to your computer and use it in GitHub Desktop.
Artisan Extended
<?php
Artisan::command('clear:cache', function () {
$this->call('view:clear');
$this->call('config:cache');
$this->call('optimize');
});
Artisan::command('clear:serve', function () {
$this->call('clear:cache');
$this->call('serve');
});
Artisan::command('make:route {name} {--api}', function () {
$name = $this->argument('name');
$controller = studly_case(class_basename($name)) . 'Controller';
$route_name = str_slug(str_plural($name));
$content = 'Route::resource(\'' . $route_name . '\', \'' . $controller . '\');' . PHP_EOL;
file_put_contents(
base_path('routes/' . ($this->option('api') ? 'api' : 'web') . '.php'),
$content,
FILE_APPEND
);
$this->info('Route created successfully.');
})->describe('Create a new resourceful route');
Artisan::command('make:mmc {model*}', function () {
$models = $this->arguments('model')['model'];
$routes = [];
foreach ($models as $key => $value) {
$value = str_singular(studly_case($value));
$this->call('make:model',
[
'name' => $value,
'-c' => true,
'-m' => true,
]
);
$this->call('make:route', [
'name' => $value,
]);
$this->call('make:request', [
'name' => $value . 'Request',
]);
}
})->describe('Create a new Model, Migration, Resourceful Controller, Route and Request');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment