Skip to content

Instantly share code, notes, and snippets.

@berkayunal
Created Nov 15, 2017
Embed
What would you like to do?
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