Open fitdev-github opened 7 months ago
As far as coding, resources don't support middleware. You can try this
$app->group('/', ['middleware' => 'auth', function () use ($app) {
app()->resource('/posts', 'PostsController');
}]);
or
$app->group('/posts', ['middleware' => 'auth', function () use ($app) {
app()->resource('/','PostsController');
}]);
I think that at a low level there could be an adapter that transforms the requested and unsupported syntax, to the supported syntax
Some adapter that transform this:
app()->resource('/posts', ['middleware'=> 'auth', 'PostController']);
to this:
app()->group('/posts', ['middleware' => 'auth', function () {
app()->resource('/', 'PostController');
}]);
I tried to do this
app()->resource('/posts', ['middleware' => 'auth','PostsController']);
but I got error
TypeError: Leaf\Router::resource(): Argument leafsphp/leaf#2 ($controller) must be of type string, array given