Laravel希望展示欢迎页面,尽管' /'路线已定义

时间:2017-09-18 10:38:33

标签: laravel laravel-5.5

我正在学习Laravel,在完成this to-do task tutorial后,我的应用仍然会继续显示默认的欢迎页面。

如果这是开发人员摆脱默认内容的机制,我也删除了resources/views/welcome.blade.php文件。但它没有任何帮助。现在所有改变的是我得到的:

  

InvalidArgumentException   查看[welcome]未找到。

FileViewFinder抛出。

我的路线根据教程在app/Http/routes.php中定义为:

/**
 * Display all tasks
 */
Route::get('/', function(){
    $tasks = Task::orderBy('created_at', 'asc')->get();

    return view('tasks', [
        'tasks' => $tasks
    ]);
});

视图在resources/views/layouts/tasks.blade.php

中创建

我不知道发生了什么......

完整堆栈跟踪:

InvalidArgumentException thrown with message "View [welcome] not found."
Stacktrace:
#51 InvalidArgumentException in /var/www/Laravel/default/vendor/laravel/framework/src/Illuminate/View/FileViewFinder.php:137
#50 Illuminate\View\FileViewFinder:findInPaths in /var/www/Laravel/default/vendor/laravel/framework/src/Illuminate/View/FileViewFinder.php:79
#49 Illuminate\View\FileViewFinder:find in /var/www/Laravel/default/vendor/laravel/framework/src/Illuminate/View/Factory.php:128
#48 Illuminate\View\Factory:make in /var/www/Laravel/default/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php:971
#47 view in /var/www/Laravel/default/routes/web.php:15
#46 Illuminate\Routing\Router:{closure} in /var/www/Laravel/default/vendor/laravel/framework/src/Illuminate/Routing/Route.php:191
#45 Illuminate\Routing\Route:runCallable in /var/www/Laravel/default/vendor/laravel/framework/src/Illuminate/Routing/Route.php:165
#44 Illuminate\Routing\Route:run in /var/www/Laravel/default/vendor/laravel/framework/src/Illuminate/Routing/Router.php:610
#43 Illuminate\Routing\Router:Illuminate\Routing\{closure} in /var/www/Laravel/default/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:30
#42 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /var/www/Laravel/default/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php:41
#41 Illuminate\Routing\Middleware\SubstituteBindings:handle in /var/www/Laravel/default/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149
#40 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /var/www/Laravel/default/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#39 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /var/www/Laravel/default/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php:67
#38 Illuminate\Foundation\Http\Middleware\VerifyCsrfToken:handle in /var/www/Laravel/default/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149
#37 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /var/www/Laravel/default/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#36 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /var/www/Laravel/default/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php:49
#35 Illuminate\View\Middleware\ShareErrorsFromSession:handle in /var/www/Laravel/default/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149
#34 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /var/www/Laravel/default/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#33 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /var/www/Laravel/default/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php:63
#32 Illuminate\Session\Middleware\StartSession:handle in /var/www/Laravel/default/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149
#31 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /var/www/Laravel/default/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#30 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /var/www/Laravel/default/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php:37
#29 Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse:handle in /var/www/Laravel/default/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149
#28 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /var/www/Laravel/default/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#27 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /var/www/Laravel/default/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php:59
#26 Illuminate\Cookie\Middleware\EncryptCookies:handle in /var/www/Laravel/default/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149
#25 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /var/www/Laravel/default/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#24 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /var/www/Laravel/default/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:102
#23 Illuminate\Pipeline\Pipeline:then in /var/www/Laravel/default/vendor/laravel/framework/src/Illuminate/Routing/Router.php:612
#22 Illuminate\Routing\Router:runRouteWithinStack in /var/www/Laravel/default/vendor/laravel/framework/src/Illuminate/Routing/Router.php:571
#21 Illuminate\Routing\Router:dispatchToRoute in /var/www/Laravel/default/vendor/laravel/framework/src/Illuminate/Routing/Router.php:549
#20 Illuminate\Routing\Router:dispatch in /var/www/Laravel/default/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:176
#19 Illuminate\Foundation\Http\Kernel:Illuminate\Foundation\Http\{closure} in /var/www/Laravel/default/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:30
#18 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /var/www/Laravel/default/vendor/fideloper/proxy/src/TrustProxies.php:56
#17 Fideloper\Proxy\TrustProxies:handle in /var/www/Laravel/default/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149
#16 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /var/www/Laravel/default/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#15 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /var/www/Laravel/default/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php:30
#14 Illuminate\Foundation\Http\Middleware\TransformsRequest:handle in /var/www/Laravel/default/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149
#13 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /var/www/Laravel/default/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#12 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /var/www/Laravel/default/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php:30
#11 Illuminate\Foundation\Http\Middleware\TransformsRequest:handle in /var/www/Laravel/default/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149
#10 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /var/www/Laravel/default/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#9 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /var/www/Laravel/default/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php:27
#8 Illuminate\Foundation\Http\Middleware\ValidatePostSize:handle in /var/www/Laravel/default/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149
#7 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /var/www/Laravel/default/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#6 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /var/www/Laravel/default/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php:46
#5 Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode:handle in /var/www/Laravel/default/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149
#4 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /var/www/Laravel/default/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#3 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /var/www/Laravel/default/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:102
#2 Illuminate\Pipeline\Pipeline:then in /var/www/Laravel/default/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:151
#1 Illuminate\Foundation\Http\Kernel:sendRequestThroughRouter in /var/www/Laravel/default/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:116
#0 Illuminate\Foundation\Http\Kernel:handle in /var/www/Laravel/default/public/index.php:58

5 个答案:

答案 0 :(得分:0)

首先更改routes/web.php的内容 Route::get('/', function () { return view('welcome'); });Route::get('/', 'YourControllerName@functionName');

然后在Controller中:

public function functionName(){
$tasks = Task::orderBy('created_at', 'asc')->get();

    return view('layouts.tasks', [
        'tasks' => $tasks
    ]);
}

或者在同一文件web.php中你可以这样做:

Route::get('/', function () { 
$tasks = \DB::table('tasks')->orderBy('created_at', 'desc')->get();
return view('layouts.tasks', [
        'tasks' => $tasks
    ]); 

});

希望有帮助

答案 1 :(得分:0)

return view('layouts.tasks', [
    'tasks' => $tasks
]);

因为你在内部文件夹中的视图,即布局

答案 2 :(得分:0)

你没有错过任何东西,但你需要用return layouts.tasks'来替换任务。在视图功能。

return view('layouts.tasks', [
    'tasks' => $tasks
]);

答案 3 :(得分:0)

有一个 web.php 文件,确保你把所有的路由都放在那里

另外,我遇​​到了和你一样的问题,并通过清除路由缓存解决了它 运行

答案 4 :(得分:0)

我遇到了同样的问题,刚刚解决了。运行此命令应该会有所帮助:

php artisan optimize:clear

它会清除所有缓存。

更多信息在这里:https://dev.to/kenfai/laravel-artisan-cache-commands-explained-41e1