V
V
Vit2016-07-31 22:16:05
Laravel
Vit, 2016-07-31 22:16:05

How to pass controller name in router.php?

Router.php has:

$this->resource('/path/settings', 'Path\Settings');
$this->resource('/path/users', 'Path\Users');
$this->resource('/path/plugins', 'Path\Plugins');

How to pass the second parameter as the name of the controller, so as not to duplicate the code?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vlad Tokarev, 2016-08-01
@reech

$pathResources = [
    'settings',
    'users',
    'plugins',
];
foreach ($pathResources as $pathResource) {
    $this->resource('/path/' . $pathResource, 'Path\\' . ucfirst($pathResource));
}

A
Alexander Aksentiev, 2016-07-31
@Sanasol

This is a perversion, so I have not seen a ready-made solution for such purposes.
So just google dynamic route controller or something like that, see how routes work, and reinvent your wheel.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question