Home » Php » simple Laravel View::make() not working

simple Laravel View::make() not working

Posted by: admin November 30, 2017 Leave a comment

Questions:

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' => '[email protected]'
));

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?

Answers:

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

Questions:
Answers:

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');
    }

}

Questions:
Answers:

Try this in your top of the class(controller)

use View;