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

In Laravel, when responding to 404 in middleware, an error is reported: View[components.css]Not found

在 Laravel 中,当在中间件中响应 404 时,报错:View [components.css] not found

1. In Laravel, when responding to 404 in the middleware, an error is reported: View[components.css]not found. as shown in Figure 1

在 Laravel 中,当在中间件中响应 404 时,报错:View [components.css] not found
Figure 1

View [components.css] not found. (View: /var/www/object/resources/views/view_object/layouts/basic.blade.php) (View: /var/www/object/resources/views/view_object/layouts/basic.blade.php) {"exception":"[object] (Illuminate\\View\\ViewException(code: 0): View [components.css] not found. (View: /var/www/object/resources/views/view_object/layouts/basic.blade.php) (View: /var/www/object/resources/views/view_object/layouts/basic.blade.php) at /var/www/object/vendor/laravel/framework/src/Illuminate/View/FileViewFinder.php:137)
[stacktrace]
#0 /var/www/object/vendor/laravel/framework/src/Illuminate/View/Engines/PhpEngine.php(45): Illuminate\\View\\Engines\\CompilerEngine->handleViewException(Object(Illuminate\\View\\ViewException), 0)
#1 /var/www/object/vendor/laravel/framework/src/Illuminate/View/Engines/CompilerEngine.php(59): Illuminate\\View\\Engines\\PhpEngine->evaluatePath('/var/www/object/...', Array)
#2 /var/www/object/vendor/laravel/framework/src/Illuminate/View/View.php(143): Illuminate\\View\\Engines\\CompilerEng...


2. Check the corresponding topic, confirm that the file /resources/views/view_object/components/css.blade.php exists. as shown in Figure 2

查看对应主题中,确认是存在文件 /resources/views/view_object/components/css.blade.php 的
Figure 2

3. The same response of 404 code, error in the middleware: View[components.css]not found. Response 404 in the controller method. Print the subject ID separately, and finally confirm that the subject ID is empty in the middleware. When looking up Components.css , will look for: /resources/views/components/css.blade.php, because I can’t find it, and then report an error. as shown in Figure 3

同样的响应 404 的代码,在中间件中报错:View [components.css] not found 。在控制器方法中响应 404。分别打印主题ID,最终确认主题ID在中间件中为空,当查找 components.css 时,会查找:/resources/views/components/css.blade.php,因为找不到,进而报错
Figure 3

var_dump(\Igaster\LaravelTheme\Facades\Theme::get());
exit;
return response()->view('errors.404', [], 404);



string(6) ""

string(6) "view_object"


4. Before responding 404 in the middleware, you need to set the theme ID first, and execute the set() of /vendor/gaster/laravel-theme/src/themes.php. No more errors, in line with expectations. as shown in Figure 4

在中间件中响应 404 之前,需要先设置主题ID,执行 /vendor/igaster/laravel-theme/src/Themes.php 的 set()。不再报错,符合预期
Figure 4

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.