So I am new to laravel and was just trying out some code to clear the basics,but however after creating a new controller to handle a route.It throws a fatal exception saying Class 'Controller' not found!
(The controller.php exists in the same directory)
The controller.php code is the default one
<?php
namespace App\Http\Controllers;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
abstract class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
}
This is my PagesController.php code
<?php
class PagesController extends Controller
{
    public function home()
    {
        $name = 'Yeah!';
        return View::make('welcome')->with('name',$name);
    }
}
This is route.php code
<?php
Route::get('/','PagesController@home');
The welcome.blade.php code is the default one except it displays the variable $name instead of laravel 5. What am I getting wrong?
When you reference a class like extends Controller PHP searches for the class in your current namespace.
In this case that's a global namespace. However the Controller class obviously doesn't exists in global namespace but rather in App\Http\Controllers.
You need to specify the namespace at the top of PagesController.php:
namespace App\Http\Controllers;
                        You will want to specify the namespace to your Controller class:
class PagesController extends \App\Http\Controllers\Controller
otherwise Controller is looked up in the default root namespace \, where it does not exist.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With