I am new to laravel 5 and currently stumped by this error:
FatalErrorException in TicketController.php line 18: Class 'App\Http\Controllers\View' not found
Weird thing is the view does in fact exist, i checked to see if the route was indeed routing to the right controller and it was, the error pops up when i try to do this:
return View::make('tickets.bus.index');
It's either i am making some mistake somewhere or if the implementation is different from laravel 4
For me it was namespace problem. I used php artisan to create controller but it seems like php artisan used different namespace (may be I have to change something in composer.json to fix it but I am totally new in laravel)
Whoops, looks like something went wrong. FatalErrorException in PagesController.php line 11: Class 'App\Http\Controllers\Controller' not found
Good that I am using phpStorm which automatically inserted proper namespacemake sure you check out namespace properly. This is how I had controller created with php artisan
and this is how phpstorm inserted after I manually wrote extends controller
There exists a helper-function, view(), which is in the global namespace, and may be used to simplify the syntax:
return view('tickets.bus.index');
The concepts that lukasgeiter explained are essential to understanding Laravel, even if you elect to use the helper-function.
In Laravel 5.1 the correct
use
code would be:use Illuminate\Support\Facades\View;
The problem is not the actual view but the class
View
. You see when you just reference a class likeView::make('tickets.bus.index')
PHP searches for the class in your current namespace.In this case that's
App\Http\Controllers
. However theView
class obviously doesn't exists in your namespace for controllers but rather in the Laravel framework namespace. It has also an alias that's in the global namespace.You can either reference the alias in the root namespace by prepending a backslash:
Or add an import statement at the top:
There exists a helper-function,
view()
, which is in the global namespace, and may be used to simplify the syntax:return view('tickets.bus.index');
With this method, it is unnecessary to include
use View;
or include the root namespace, e.g.,\View
.The concepts that lukasgeiter explained are essential to understanding Laravel, even if you elect to use the helper-function.