Reputation: 21
I started using Laravel today, but I have some problems. Controllers don't run.
This is my controller:
<?php
class HomeController extends Controller {
/*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
}
/**
* Show the application welcome screen to the user.
*
* @return Response
*/
public function index()
{
return view('welcome');
}
public function contact(){
return view(pages.contact);
}
?>
and this is my route:
<?php
Route::get('/', function () {
return "hello";
});
Route::get('contact','HomeController@contact');
?>
Upvotes: 0
Views: 185
Reputation: 2023
You need to add the namespace to the beginning of the controller:
<?php
namespace App\Http\Controllers;
You can also run this command when creating a controller
php artisan make:controller HomeController
In, addition as the other answer mentioned, the view name needs to be inside quotes.
Hope this helps.
Upvotes: 2
Reputation: 6269
This should be like this
public function contact(){
return view('pages.contact'); // View name must be inside ' '
}
also you dont need the closing tag for php ?>
Upvotes: 0