Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

simple Laravel View::make() not working

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?

like image 553
ryndshn Avatar asked Mar 06 '15 05:03

ryndshn


3 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

like image 161
mininoz Avatar answered Nov 18 '22 12:11

mininoz


Try this in your top of the class(controller)

use View;
like image 4
Raham Avatar answered Nov 18 '22 14:11

Raham


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

}
like image 1
kylehyde215 Avatar answered Nov 18 '22 14:11

kylehyde215