use this helper functions they may help you a little bit...
they allow you to write :
- ( it does not break the default syntax )
get( '/url' , 'HomeController@index (routeName) | auth,logger '); //instead of :
get( '/' , ['as'=>'routeName' , 'uses'=>'HomeController@index' , 'middleware'=>['auth' , 'logger']]); // would be still valid
note that these are treated as the same
get( '/url' , 'HomeController@index (routeName) | auth , logger ');
get( '/url' , 'HomeController@index ( routeName ) | [auth,logger] ');
get( '/url' , 'HomeController@index (routeName) | ["auth","logger"] ');
(put them in a some-file.php and require the in your bootstrap/autoload.php BEFORE the autoload.php)
require DIR.'/../some-file.php';
require DIR.'/../vendor/autoload.php';
function get( $uri , $action )
{
$options = parse_action( $action );
return app( 'router' )->get( $uri , $options );
}
function post( $uri , $action )
{
$options = parse_action( $action );
return app( 'router' )->post( $uri , $options );
}
function put( $uri , $action )
{
$options = parse_action( $action );
return app( 'router' )->put( $uri , $options );
}
function patch( $uri , $action )
{
$options = parse_action( $action );
return app( 'router' )->patch( $uri , $options );
}
function delete( $uri , $action )
{
$options = parse_action( $action );
return app( 'router' )->delete( $uri , $options );
}
function parse_action( $action )
{
if( is_array( $action ) )
return $action;
$action = preg_replace( '/\s*?/' , '' , $action ); //stripes spaces
$action = preg_replace( '/(.*)\[(.*)\](.*)/' , '$1$2$3' , $action );//stripes [ and ]
$action = preg_replace( '/[\'"]/' , '' , $action ); //stripes ' and "
$options[ 'middleware' ] = null;
$options[ 'as' ] = null;
$options[ 'uses' ] = null;
if( preg_match( '/.*?\|.*/' , $action ) ) //if it has middleware
{
$middles = preg_replace( '/.*\|(.*)/' , '$1' , $action );
$options[ 'middleware' ] = explode( ',' , $middles );
$action = preg_replace( '/(.*)(\|.*)/' , '$1' , $action ); //detach the middleware from the end of action string
}
if( preg_match( '/.*?\(.*?\)/' , $action ) )// if it has route name in ()
{
$options[ 'as' ] = preg_replace( '/.*?\((.*?)\)/' , '$1' , $action ); // find the routeName
$action = preg_replace( '/(.*?)\((.*?)\)/' , '$1' , $action ); // delete the routeName
}
$options[ 'uses' ] = $action;
return $options;
}