In Laravle 6, simulate a route requesting a resource file, and the data is fetched from the database
1. The route of a requesting resource file is as follows: /static/xxx/9915995c-2952-4 90c-8e51-037a0950233c/assets/js/react.f886be.js
2. Since / is included in asset_key. Laravel routing components allow all characters except / . You must explicitly allow / to be part of a placeholder using the WHERE conditional regular expression. Otherwise, the route will fall back. The routes/web.php file is used to define routes to the web interface.
Route::get('/static/xxx/{theme_id}/{asset_key}', 'ModelController@show')->where('asset_key', '.*');
3. Openhttps://regex101.com/, to confirm that the regular expression .* can match assets/js/react.f886be.js. as shown in Figure 1
4. The method of the corresponding controller is implemented as follows. Because it needs to comply with the last-modified specification, use DATE_RFC7231, RFC 7231 format (example: SAT, 30 APR 2016) 17:52:13 GMT). as shown in Figure 2
$model = Model::where('theme_id', '=', $themeId)->where('asset_key', '=', $assetKey)->where('category', '=', Model::CATEGORY_ASSET)->firstOrFail();
return response($model->content, 200)
->withHeaders([
'Content-Type' => $model->mime_type,
'Last-Modified' => date(DATE_RFC7231, strtotime($model->getOriginal('updated_at'))),
]);

