第一次Laravel面临NotFoundHttpException

时间:2015-06-12 09:16:59

标签: php laravel laravel-5

我跟随flynsarmys' laravel tutorial。一切顺利,直到我把ProjectsController的索引放到第二部分,当我测试导航到浏览器中的15todo.app:8000/projects时,应用程序抛出NotFoundHttpException。

routes.php文件

Route::get('/', function () {
    return view('welcome');
});

Route::resource('projects', 'ProjectsController');
// Route::resource('tasks', 'TasksController');
Route::resource('projects.tasks', 'TasksController');

Route::bind('tasks', function($value, $route) {
    return App\Task::whereSlug($value)->first();
});
Route::bind('projects', function($value, $route) {
    return App\Project::whereSlug($value)->first();
});

ProjectsController.php

public function index()
{
    return view('projects.index');
}

我用Google搜索和搜索,但我仍然无法找到发生这种情况的线索。如果我检查了php artisan route:list就像这样显示

$ php artisan route:list
+--------+----------+----------------------------------------+------------------------+-------------------------------------------------+------------+
| Domain | Method   | URI                                    | Name                   | Action                                          | Middleware |
+--------+----------+----------------------------------------+------------------------+-------------------------------------------------+------------+
|        | GET|HEAD | /                                      |                        | Closure                                         |            |
|        | GET|HEAD | projects                               | projects.index         | App\Http\Controllers\ProjectsController@index   |            |
|        | GET|HEAD | projects/create                        | projects.create        | App\Http\Controllers\ProjectsController@create  |            |

我做错了什么?帮助......

我的开发环境是窗户上的家园。对于控制台我使用Git Bash(MinGW)。我的15todo.app:8000已经启动并显示" Laravel 5"关于简单性的随机引用。

1 个答案:

答案 0 :(得分:0)

您需要实际创建视图。将其作为/app/resources/views/projects/保存在index.blade.php目录中。参考观点文档here

您可以创建新的PHP / HTML文件,但最佳做法是使用Blade模板引擎。例如:

    @extends('app')
        @section('content')
            <!-- your content here -->
            {{ 'escaped string' }}
            {!! 'non escaped <strong>string</strong>' !!}
        @endsection
    @stop

详细了解该视图的文档,并观看此视频on Laracasts