简单 Laravel View::make() 不工作

simple Laravel View::make() not working

所以我正在学习一些基本的 Laravel 东西,因为我是 PHP 的新手。 我正在学习一个基本教程,该教程让我将内容打印到名为 home.blade.php 的文件中。

我现在的调用方式如下。

这是我的routes.php

Route::get('/', array(
    'as' => 'home',
    'uses' => 'HomeController@home'
));

这是我的 HomeController.php

class HomeController extends Controller {

    public function home() {
        return View::make('home');
    }

}

这里是home.blade.php

{{'Hello.'}}

在你问之前,是的,我的 home.blade.php 在我的 Views 文件夹中。

错误打印如下

FatalErrorException in HomeController.php line 6:
Class 'App\Http\Controllers\View' not found
in HomeController.php line 6
at HandleExceptions->fatalExceptionFromError(array('type' => '1', 'message' => 'Class 'App\Http\Controllers\View' not found', 'file' => '/Users/ryandushane/Google Drive/Web_WorkSpace/theNeonSurf/app/Http/Controllers/HomeController.php', 'line' => '6')) in compiled.php line 1738
at HandleExceptions->handleShutdown()

这是奇怪的部分。如果我将 routes.php 更改为仅包含

Route::get('/', function()
{
    return View::make('home');
});

运行良好。

有人知道我能做什么吗?

我打赌你的控制器 class 有一个命名空间,是吗?尝试 \View::make('home'); 或者您可以在文件顶部导入它:

<?php

namespace App\Http\Controllers;

use View;

class HomeController extends Controller {

    public function home() {
        return View::make('home');
    }

}

Laravel 5

的新语法
public function home() {
    return view('home');
}

有关更多信息,您可以从此处阅读 http://laravel.com/docs/5.0/views

在 class(控制器)

的顶部试试这个
use View;