In Laravel, when responding to 404 in middleware, an error is reported: 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
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
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
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
![在 Laravel 中,当在中间件中响应 404 时,报错:View [components.css] not found](https://www.shuijingwanwq.com/wp-content/uploads/2023/05/1.png)

![同样的响应 404 的代码,在中间件中报错:View [components.css] not found 。在控制器方法中响应 404。分别打印主题ID,最终确认主题ID在中间件中为空,当查找 components.css 时,会查找:/resources/views/components/css.blade.php,因为找不到,进而报错](https://www.shuijingwanwq.com/wp-content/uploads/2023/05/3.png)
