Skip to content

Instantly share code, notes, and snippets.

@berkayunal
Created November 15, 2017 12:36
Show Gist options
  • Save berkayunal/644c03c661dc68b7d9eab383378d21d6 to your computer and use it in GitHub Desktop.
Save berkayunal/644c03c661dc68b7d9eab383378d21d6 to your computer and use it in GitHub Desktop.
Simple routing for Laravel test controllers
<?php
/**
* Routes
*
* Example:
* http://localhost/test/hello/me/param1/param2
* http://localhost/test/hello/there/param1/param2
*/
Route::group(['prefix' => 'test'], function () {
Route::any('{controller}/{method?}/{params?}', function ($controller = "", $method = "index", $params = "") {
app()
->make('\App\Http\Controllers\Test\\' . ucfirst($controller) . 'Controller')
->callAction($method, explode('/', $params));
})->where('params', '.*');
});
/*
* File: app/Http/Controllers/Test/HelloController.php
*/
namespace App\Http\Controllers\Test;
use App\Http\Controllers\Controller;
class HelloController extends Controller
{
public function me(...$params)
{
dump($params);
}
public function there(...$params)
{
dump($params);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment