Laravel 5.3 - InvalidArgumentException 视图 [索引] 未找到 [重复]

Posted

技术标签:

【中文标题】Laravel 5.3 - InvalidArgumentException 视图 [索引] 未找到 [重复]【英文标题】:Laravel 5.3 - InvalidArgumentException View [index] not found [duplicate] 【发布时间】:2017-05-29 21:03:00 【问题描述】:

已经将我的 Laravel 应用部署到我的 VPS 中。它在本地主机上运行良好。我认为错误出在我的路由或控制器中,因为路径仍在我的本地机器目录中(参见错误消息第 2 行),但我真的看不出代码中的问题。

我尝试过使用php artisan config:cachephp artisan cache:clearphp artisan route:cache,但还是不行。它仍然引用我的本地机器目录。

这是index.blade.php的目录

Root
|-- portofolio
    |-- app
    |-- bootstrap
    |-- config
    |-- database
    |-- resources
        |-- assets
        |-- lang
        |-- views
            |-- index.blade.php
    |-- routes
    |-- storage
    |-- tests
    |-- vendor
|-- public_html
    |-- css
    |-- img
    |-- js
    |-- vendor

这是路线

Route::get('/', ['as' => 'home', 'uses' => 'Portofolio@link']);

这是控制器

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class Portofolio extends Controller

public function link() 

    $categories = [
        '1' => 'Print Design',
        '2' => 'Logo Design',
        '3' => 'Web Design',
        '4' => 'Product Design',
        '5' => 'Character Design',
        '6' => 'Packaging Design'
    ];

    $projects = [
        '1' => 'IMSAA Training Certificate',
        '2' => 'Rusticity Logo',
        '3' => 'Handy Production Website',
        '4' => 'Nihon no Matsuri Bag Project',
        '5' => 'The Chin - Captain Jack Sparrow',
        '6' => 'Rusticity Packaging'
    ];

    $images = [
        '1' => '1',
        '2' => '2',
        '3' => '3',
        '4' => '4',
        '5' => '5',
        '6' => '6'
    ];

    $skills = [
        '1' => 'Photoshop',
        '2' => 'Ms. Office',
        '3' => 'Laravel',
        '4' => 'PHP',
        '5' => 'HTML',
        '6' => 'mysql'
    ];

    $points = [
        '1' => '80%',
        '2' => '90%',
        '3' => '60%',
        '4' => '60%',
        '5' => '60%',
        '6' => '60%'
    ];

    return view('index')->withCategories($categories)->withProjects($projects)->withImages($images)->withSkills($skills)->withPoints($points);


这是错误信息(见第 2 行)

InvalidArgumentException in FileViewFinder.php line 137:

View [index] not found.

1.  in FileViewFinder.php line 137
2.  at FileViewFinder->findInPaths('index', array('E:\Laravel\portofolio\resources\views')) in FileViewFinder.php line 79
3.  at FileViewFinder->find('index') in Factory.php line 174
4.  at Factory->make('index', array(), array()) in helpers.php line 856
5.  at view('index') in Portofolio.php line 56
6.  at Portofolio->link()
7.  at call_user_func_array(array(object(Portofolio), 'link'), array()) in Controller.php line 55
8.  at Controller->callAction('link', array()) in ControllerDispatcher.php line 44
9.  at ControllerDispatcher->dispatch(object(Route), object(Portofolio), 'link') in Route.php line 190
10. at Route->runController() in Route.php line 144
11. at Route->run(object(Request)) in Router.php line 653
12. at Router->Illuminate\Routing\closure(object(Request)) in Pipeline.php line 53
13. at Pipeline->Illuminate\Routing\closure(object(Request)) in SubstituteBindings.php line 41
14. at SubstituteBindings->handle(object(Request), object(Closure)) in Pipeline.php line 137
15. at Pipeline->Illuminate\Pipeline\closure(object(Request)) in Pipeline.php line 33
16. at Pipeline->Illuminate\Routing\closure(object(Request)) in VerifyCsrfToken.php line 65
17. at VerifyCsrfToken->handle(object(Request), object(Closure)) in Pipeline.php line 137
18. at Pipeline->Illuminate\Pipeline\closure(object(Request)) in Pipeline.php line 33
19. at Pipeline->Illuminate\Routing\closure(object(Request)) in ShareErrorsFromSession.php line 49
20. at ShareErrorsFromSession->handle(object(Request), object(Closure)) in Pipeline.php line 137
21. at Pipeline->Illuminate\Pipeline\closure(object(Request)) in Pipeline.php line 33
22. at Pipeline->Illuminate\Routing\closure(object(Request)) in StartSession.php line 64
23. at StartSession->handle(object(Request), object(Closure)) in Pipeline.php line 137
24. at Pipeline->Illuminate\Pipeline\closure(object(Request)) in Pipeline.php line 33
25. at Pipeline->Illuminate\Routing\closure(object(Request)) in AddQueuedCookiesToResponse.php line 37
26. at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) in Pipeline.php line 137
27. at Pipeline->Illuminate\Pipeline\closure(object(Request)) in Pipeline.php line 33
28. at Pipeline->Illuminate\Routing\closure(object(Request)) in EncryptCookies.php line 59
29. at EncryptCookies->handle(object(Request), object(Closure)) in Pipeline.php line 137
30. at Pipeline->Illuminate\Pipeline\closure(object(Request)) in Pipeline.php line 33
31. at Pipeline->Illuminate\Routing\closure(object(Request)) in Pipeline.php line 104
32. at Pipeline->then(object(Closure)) in Router.php line 655
33. at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 629
34. at Router->dispatchToRoute(object(Request)) in Router.php line 607
35. at Router->dispatch(object(Request)) in Kernel.php line 268
36. at Kernel->Illuminate\Foundation\Http\closure(object(Request)) in Pipeline.php line 53
37. at Pipeline->Illuminate\Routing\closure(object(Request)) in CheckForMaintenanceMode.php line 46
38. at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 137
39. at Pipeline->Illuminate\Pipeline\closure(object(Request)) in Pipeline.php line 33
40. at Pipeline->Illuminate\Routing\closure(object(Request)) in Pipeline.php line 104
41. at Pipeline->then(object(Closure)) in Kernel.php line 150
42. at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 117
43. at Kernel->handle(object(Request)) in index.php line 54

【问题讨论】:

你的资源/视图文件夹/文件结构是什么 检查index文件的路径。 你在哪里 index.blade.php???? 你的 index.blade.php 应该在 resources/views/ 文件夹中 是的,我的 index.blade.php 在资源/视图文件夹中 【参考方案1】:

确保views目录中有index.blade.php,这里index.blade.php不是/dir中的index.php。

【讨论】:

是的,它在views目录中 更清楚一点,当我将它部署在我的 VPS 上时发生了这个错误,它在 localhost 上工作正常 检查你的 apache conf 的根目录【参考方案2】:

我已经解决了这个问题。

问题是我的服务器没有正确设置,因为域没有正确连接到我的 VPS。联系了托管服务商,问题解决了。

如果有人遇到这个问题,请检查

    您是否已经完成php artisan config:cachephp artisan config:clear? 您是否正确地将视图命名为yourview.blade.php? 您是否在resources\views 中正确放置了视图?

【讨论】:

以上是关于Laravel 5.3 - InvalidArgumentException 视图 [索引] 未找到 [重复]的主要内容,如果未能解决你的问题,请参考以下文章

laravel 无法打开输入文件:artisan (5.3)

Laravel 5.3 密码代理自定义

从 Laravel 5.3 升级到 Laravel 5.4 并且空字段转换为 NULL

laravel 路由重定向问题(laravel 5.3)

Laravel 5.3 用户模型中的 CanResetPassword

Laravel 5.2 或 5.3:如何正确实施检查会话是不是已登录