Hi ! I had the same problem. I added this function to Laravel\Lumen\Application.php
/**
* Register a resource with the application.
*
* @param string $uri
* @param mixed $controller
* @return $this
*/
public function resource($uri, $controller)
{
$this->get($uri, 'App\Http\Controllers\\'.$controller.'@index');
$this->get($uri.'/create', 'App\Http\Controllers\\'.$controller.'@create');
$this->post($uri, 'App\Http\Controllers\\'.$controller.'@store');
$this->get($uri.'/{id}', 'App\Http\Controllers\\'.$controller.'@show');
$this->get($uri.'/{id}/edit', 'App\Http\Controllers\\'.$controller.'@edit');
$this->put($uri.'/{id}', 'App\Http\Controllers\\'.$controller.'@update');
$this->patch($uri.'/{id}', 'App\Http\Controllers\\'.$controller.'@update');
$this->delete($uri.'/{id}', 'App\Http\Controllers\\'.$controller.'@destroy');
return $this;
}
Plus there was an existing answer to lumen routing === http://laravel.io/forum/04-25-2015-lumen-generic-controller-route-fails-but-worked-in-laravel
You can follow what @diegomariani did. While you're at it, check this out:
If you're having to go through all that you may as well just install and use Laravel.
The lumen docs shows how to route. But it's in the controllers section of the docs. If you have to keep adding tons of code to make lumen work like laravel, yek may as well use laravel. But you have good code, and your code is always useful.
jimgwhit said:
If you're having to go through all that you may as well just install and use Laravel.
Sorry to revive an old thread, but I keep seeing this dismissive kind of response to this question everywhere and I feel it's the kind of thinking that discourages people from trying to make something better. Resource routing is not an unreasonable wish for Lumen. Lumen is geared toward developing APIs. I actually care more about my APIs following good REST conventions than I do about apps that render HTML, most of the time. IMO Lumen ought to make it easy.
I presume that Lumen doesn't have resource routing (yet) because its router is based on FastRoute instead of Laravel's router, so work of implementing resource routing on top of it just hasn't been done yet. I bet it's achievable without a serious performance sacrifice. I'd love to see it proposed as a feature for future versions.
Thanks @diegomariani and @beanmoss for sharing your code, very handy.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community