asvae / laravel-api-tester

Test your routes without hassle
http://laravel-api-tester.asva.by/
MIT License
356 stars 52 forks source link

Using _file instead of file for correct routing #44

Closed kadriev-ilyas closed 4 years ago

kadriev-ilyas commented 4 years ago

Using Str::contains instead of deprecated str_contains https://laravel.com/docs/5.8/helpers#method-str-contains

asvae commented 4 years ago

Thanks for PR!

Can you explain why we need _file? I googled a bit, but didn't find anything relevant.

kadriev-ilyas commented 4 years ago

Thanks for PR!

Can you explain why we need _file? I googled a bit, but didn't find anything relevant.

It is because you use "_file" variable in routing rules:

// Instead we'll pass them via app which is slower but fine for development.
$router->group(['prefix' => 'assets'], function ($router) {

    $filePattern = '^([a-z0-9_\-\.]+)$';

    $router->get('fonts/{_file}', [
        'as' => 'image',
        'uses' => 'AssetsController@font'
    ])->where('_file', $filePattern);

    $router->get('img/{_file}', [
        'as' => 'image', 'uses' => 'AssetsController@image'
    ])->where('_file', $filePattern);

    $router->get('{_file}', [
        'as' => 'file',
        'uses' => 'AssetsController@index'
    ])->where('_file', $filePattern);
});

And construction like this:

{{ route('api-tester.file', ['_file' => 'api-tester.js']) }} trying to find route api-tester.file and place 'api-tester.js' instead of _file variable.

In your code you use file and this variable not exists in rules and nothing returning by this rule

asvae commented 4 years ago

Got it. Thanks!