A
A
Anna2018-12-03 18:17:44
Laravel
Anna, 2018-12-03 18:17:44

Is it possible to change the controller?

Requests are coming

Route::get('/{ver}/d/{guid}',['uses'=>'[email protected]']);

So, my {ver} is changing. Accordingly, in the Controlles folder there is a Files folder
. It contains folders 0.1 0.2 How to force using {ver} to access the desired folder. The controller name does not change. That is, it should return Files\{ver}\[email protected]

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Andrey Helldar, 2018-12-04
@Helldar

The names of methods, classes, namespaces, functions, and so on must always begin with a letter.
It is also customary in Lara to name methods in the camelCase format.

Route::get('1.0/d/{guid}', 'Files\v1b0\[email protected]');

Route::get('2.0/d/{guid}', 'Files\v2b0\[email protected]');

Route::get('2.1/d/{guid}', 'Files\v2b1\[email protected]');

K
Konstantin B., 2018-12-04
@Kostik_1993

Something like this, it is not necessary that it will work, but the direction is if I understand you correctly

Route::get('/{ver}/d/{guid}', function($ver, $guid) {
        $class = '\\App\\Http\\Controllers\\Files\\'.$ver.'\\Files';
        $controller = new $class();
        return $controller->index($guid);
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question