There is no problem not worth solving, and no technology not worth learning!

In Laravle 6, simulate a route requesting a resource file, and the data is fetched from the database

在对应控制器的方法实现如下,由于需要符合 Last-Modified 规范,使用了 DATE_RFC7231,RFC 7231 格式 (示例:Sat, 30 Apr 2016 17:52:13 GMT)

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

打开 https://regex101.com/ ,确认正则表达式 .* 可以匹配上 assets/js/react.f886be.js
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

在对应控制器的方法实现如下,由于需要符合 Last-Modified 规范,使用了 DATE_RFC7231,RFC 7231 格式  (示例:Sat, 30 Apr 2016 17:52:13 GMT)
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'))),
	]);


PHP / Laravel / Yii2 Legacy Project Maintenance & Long-Term Technical Support

If your PHP / Laravel / Yii2 project is already in production but needs bug fixing, API troubleshooting, performance optimization, developer handover support, or long-term maintenance, feel free to contact me for remote technical support.

Ideal For:
✅ PHP legacy systems without active maintenance
✅ Laravel / Yii2 project bug fixes
✅ Admin panel feature iterations
✅ RESTful API troubleshooting
✅ MySQL / Redis / Nginx performance issues
✅ Long-term remote part-time maintenance

We can start with a small task:
✅ Production error troubleshooting
✅ API issue analysis
✅ Slow query and performance bottleneck diagnosis
✅ Initial code structure review
✅ Deployment environment and log inspection

If you would like to discuss your project, please contact me and mention: PHP Maintenance Consultation.

Contact Me:
Telegram: @shuijingwan
WeChat: 13980074657
Email: shuijingwanwq@gmail.com

评论

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.