Created
November 15, 2017 12:36
-
-
Save berkayunal/644c03c661dc68b7d9eab383378d21d6 to your computer and use it in GitHub Desktop.
Simple routing for Laravel test controllers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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