Reputation: 119
I'm trying to learn how to use Laravel 5, but I've bumped into a problem. I've created the following code so far:
under app/HTTP/routes.php
:
<?php
Route::get('/', 'MyController@home');
Created my own MyController.php
file under app\Http\Controllers
and added the following code to the controller:
<?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);
}
}
When I run the app I get the error:
FatalErrorException in MyController.php line 12:
Class 'App\Http\Controllers\View' not found
What am I doing wrong?
Upvotes: 11
Views: 33768
Reputation: 10300
Change
return View::make("index")->with("name", $name);
To
return \View::make("index")->with("name", $name);
or Even better
return view("index",compact('name'));
UPDATE
View
is a Facade
, a wrapper class, and view()
is a helper function that retrives a view
instance.
Upvotes: 13