1

我试图弄清楚为什么我的路线会引发 404 错误而不是提供我的图像。我正在使用 Spatie 媒体库来提供私人图像。

我有以下路线web.php:

Auth::routes();

Route::get('/home', 'HomeController@index')->name('home');

Route::middleware(['auth'])->group(function () {
    Route::get('/images/{$gift}/{$uuid}', 'ImageController@show')->name('images.show');
    Route::resource('games', 'GameController');
    Route::resource('players', 'PlayerController');
});

Route::get('/', function () {
    return view('welcome');
});

当我这样做时: {{ route('images.show', [$gift, $gift->getFirstMedia()->uuid]) }}在我的刀片中,正确生成了 URL。但是,单击该链接会导致 404 错误。

ImageController@show 函数存在,并且目前仅执行此操作,dd('here');因此我确信 Laravel 甚至从未尝试调用该函数。

此外,我的 laravel.log 文件中目前没有任何内容。此 404 错误不会生成日志条目。

谢谢您的帮助!

4

1 回答 1

1

在 URI 中定义路由参数时,它们只是名称,而不是 PHP 变量:

'/images/{$gift}/{$uuid}' 

应该:

'images/{gift}/{uuid}'
于 2020-12-16T02:06:08.397 回答