for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Loadsman\LaravelPlugin\Providers;
use Illuminate\Support\ServiceProvider;
/**
* Macroses for macroable services.
*/
class MacroServiceProvider extends ServiceProvider
{
public function register()
* Present controller method as `post` route.
app('router')->macro('expose',
function ($controller = '', Array $actions) {
foreach ($actions as $action) {
$this->post(snake_case($action, '-'),
$controller.'@'.$action);
}
});
* Expose all public methods of controller.
* @see `expose` macro /\
app('router')->macro('exposeAll', function ($controllerClassName) {
$controllerClassReflection = new \ReflectionClass($controllerClassName);
$publicActions = $controllerClassReflection->getMethods(\ReflectionMethod::IS_PUBLIC);
foreach ($publicActions as $publicAction) {
$declaringClass = $publicAction->getDeclaringClass()->getName();
$isOwn = $declaringClass === $controllerClassName;
if (! $isOwn) {
continue;
$action = $publicAction->getName();
$controllerClassName.'@'.$action);