Laravel:从控制器返回视图

n0t*_*b3R 8 php xampp laravel

我正在努力学习如何使用Laravel 5,但我遇到了一个问题.我创建了下面的代码至今:

app/HTTP/routes.php:

<?php

Route::get('/', 'MyController@home');
Run Code Online (Sandbox Code Playgroud)

创建了我自己的MyController.php文件app\Http\Controllers,并将以下代码添加到控制器:

<?php

namespace App\Http\Controllers;

use Illuminate\Routing\Controller as BaseController;

class MyController extends BaseController
{
    public function home()
    {
        $name = "John Doe";
        return View::make("index")->with("name", $name);
    }
}
Run Code Online (Sandbox Code Playgroud)


当我运行应用程序时,我收到错误:

FatalErrorException in MyController.php line 12:
Class 'App\Http\Controllers\View' not found
Run Code Online (Sandbox Code Playgroud)


我究竟做错了什么?

pin*_*sia 9

更改

return View::make("index")->with("name", $name);
Run Code Online (Sandbox Code Playgroud)

return \View::make("index")->with("name", $name);
Run Code Online (Sandbox Code Playgroud)

或者甚至更好

return view("index",compact('name'));
Run Code Online (Sandbox Code Playgroud)

UPDATE

View是一个Facade包装类,view()是一个帮助函数来检索view实例.