7

So I'm learning some basic Laravel stuff as I am new to PHP. I am following a basic tutorial that is having me print stuff to a file named home.blade.php.

The way I am calling it now is as follows.

Here is my routes.php

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

Here is my HomeController.php

class HomeController extends Controller {

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

}

Here is home.blade.php

{{'Hello.'}}

Before you ask, yes my home.blade.php is inside of my Views folder.

The error print out is as follows

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()

Here's the odd part. If I change my routes.php to simply contain

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

it functions fine.

Does anyone have an idea of what I could do?

ryndshn
  • 692
  • 2
  • 13
  • 30

3 Answers3

14

New syntax for Laravel 5

public function home() {
    return view('home');
}

For more information you can read it from here http://laravel.com/docs/5.0/views

mininoz
  • 5,908
  • 4
  • 23
  • 23
  • Ahhh. Makes sense. A lot of their documentation still shows `View::make()` which is why I was confused. – ryndshn Mar 06 '15 at 06:07
4

Try this in your top of the class(controller)

use View;
Raham
  • 4,781
  • 3
  • 24
  • 27
1

I bet your controller class has a namespace, yes? Try \View::make('home'); Or you can import it in the top of the file:

<?php

namespace App\Http\Controllers;

use View;

class HomeController extends Controller {

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

}
kylehyde215
  • 1,216
  • 1
  • 11
  • 18
  • can you tell me why this works? You're correct. thanks for you're help! is this new in Laravel 5? (the tutorial I'm following is from Laravel 4) – ryndshn Mar 06 '15 at 05:54
  • It's not new for laravel 5. When you are inside a namespace in php, all classes outside of the namespace need to be prefixed with "\" or need to be imported with the `use` statement. Without the "\", you were actually saying class `App\View` which obviously doesn't exist. – kylehyde215 Mar 06 '15 at 05:57
  • doing `return \View::make('home');` works. However `use View;` does not. – ryndshn Mar 06 '15 at 05:58