56

I have problem with laravel view is not found by route function I did composer dumpautoload but no use ArticleController.php

<?php
class ArticleController extends BaseController
 {
 public function showIndex()
 {
    return View::make('index');
 }

 public function showSingle($articleId)
 {
 return View::make('single');
 }
}


//Route
Route::get('index', 'ArticleController@showIndex');

InvalidArgumentException

View [index] not found.
open: /opt/lampp/htdocs/laravel-project/bootstrap/compiled.php

    foreach ((array) $paths as $path) {
    foreach ($this->getPossibleViewFiles($name) as $file) {
    if ($this->files->exists($viewPath = $path . '/' . $file)) {
    return $viewPath;
    }
    }
    }
    throw new \InvalidArgumentException("View [{$name}] not found.");
    }
    protected function getPossibleViewFiles($name)

Server/Request Data
REDIRECT_UNIQUE_ID  UfWlAn8AAQEAABR2VakAAAAF
REDIRECT_STATUS     200
UNIQUE_ID   UfWlAn8AAQEAABR2VakAAAAF
HTTP_HOST   localhost
HTTP_USER_AGENT     Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:22.0) Gecko/20100101 Firefox/22.0
HTTP_ACCEPT     text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
HTTP_ACCEPT_LANGUAGE    en-US,en;q=0.5
HTTP_ACCEPT_ENCODING    gzip, deflate
HTTP_COOKIE     laravel_session=f94fpel78jn89nhah32mflqn15
HTTP_CONNECTION     keep-alive
HTTP_CACHE_CONTROL  max-age=0
PATH    /usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
LD_LIBRARY_PATH     /opt/lampp/lib:/opt/lampp/lib
SERVER_SIGNATURE    
SERVER_SOFTWARE     Apache/2.4.4 (Unix) OpenSSL/1.0.1e PHP/5.4.16 mod_perl/2.0.8-dev Perl/v5.16.3
SERVER_NAME     localhost
SERVER_ADDR     127.0.0.1
SERVER_PORT     80
REMOTE_ADDR     127.0.0.1
DOCUMENT_ROOT   /opt/lampp/htdocs
REQUEST_SCHEME  http
CONTEXT_PREFIX  
CONTEXT_DOCUMENT_ROOT   /opt/lampp/htdocs
SERVER_ADMIN    [email protected]
SCRIPT_FILENAME     /opt/lampp/htdocs/laravel-project/public/index.php
REMOTE_PORT     50211
REDIRECT_URL    /laravel-project/public/index
GATEWAY_INTERFACE   CGI/1.1
SERVER_PROTOCOL     HTTP/1.1
REQUEST_METHOD  GET
QUERY_STRING    
REQUEST_URI     /laravel-project/public/index
SCRIPT_NAME     /laravel-project/public/index.php
PHP_SELF    /laravel-project/public/index.php
REQUEST_TIME_FLOAT  1375053058.123
REQUEST_TIME    1375053058
6
  • 2
    Do you have a index.php or index.blade.php file in your app/views directory? Commented Jul 28, 2013 at 23:30
  • 1
    That's your problem. You have to actually create the view file... if you do View::make('index'), Laravel will look for a file named 'index' (ending with .php or .blade.php) under your app/views directory. Commented Jul 28, 2013 at 23:32
  • just I want to ask when you call View::make('index'); will create view Commented Jul 28, 2013 at 23:39
  • 2
    Laravel will create the view from your view file. When you do View::make Laravel will actually find the view file specified then inflate it with view data. So you it is mandatory for you to create your view file. Laravel will not make it for you. Commented Jul 28, 2013 at 23:41
  • even i am also getting same issue,i have install laravel passport in my project i dnt no why it is happening.,if anyone knows pls let me know Commented Nov 23, 2018 at 12:38

22 Answers 22

62

This error also occurs when you try to move the whole project directory to other path. And you happened to run the following commands below BEFORE you move.

php artisan optimize --force
php artisan config:cache
php artisan route:cache

Mine error message shows like this enter image description here

As you can see the old path was written in the compiled.php. So, to fix the problem. Simply run the same command AGAIN under the project folder in your new folder location.

php artisan optimize --force
php artisan config:cache
php artisan route:cache

Hope this helps.

Sign up to request clarification or add additional context in comments.

5 Comments

This comment was immensely useful in tracking down this bug. We only encountered this issue when we deployed to our AWS cloud -- we couldn't reproduce the issue locally. For anyone else deploying to AWS via Elastic Beanstalk, you'll need to run these commands AFTER the deployment has completed; in other words, via a post-deployment hook: forums.aws.amazon.com/thread.jspa?messageID=678066
If you are using Homestead, you will have to mind to execute those commands inside your vagrant box and login in with vagrant ssh.
@SamuelMS can you share what you had on your post-deployment script? I'm running php artisan config:cache but the env() calls are not resolving so the generated config cache file has all the default values.
I was able to fix it by doing source /opt/elasticbeanstalk/support/envvars before php artisan config:cache
If you're on docker and using persistent volumes mapped to your local drive, ensure you run the artisan commands in the docker container and not your local mapped drive.
47

This happens when Laravel doesn't find a view file in your application. Make sure you have a file named: index.php or index.blade.php under your app/views directory.

Note that Laravel will do the following when calling View::make:

  • For View::make('index') Laravel will look for the file: app/views/index.php.
  • For View::make('index.foo') Laravel will look for the file: app/views/index/foo.php.

The file can have any of those two extensions: .php or .blade.php.

Comments

24

This command works for me

php artisan config:cache

As Laravel doc says that by default, Laravel is configured to use the file cache driver, which stores the serialized, cached objects in the filesystem. So it needs to recache the file system so that newly added views and route are available to show. I also not sure why laravel needs to recache actually

1 Comment

So far I understand, laravel doc says that by default, Laravel is configured to use the file cache driver, which stores the serialized, cached objects in the filesystem. So it needs to recache the file system so that newly added views and route are available to show. I also not sure why laravel needs to recache actually ):
12

In my case I had to run php artisan optimize:clear in order to make everything to work again.

Comments

9

This might be possible that your view is present even though it shows the error. So to solve this issue you need to stop the server and run this command on the terminal.

php artisan config:cache

then restart the server

1 Comment

To give your application a speed boost, you should cache all of your configuration files into a single file using the 'config:cache' Artisan command. This will combine all of the configuration options for your application into a single file which will be loaded quickly by the framework. You should typically run the 'php artisan config:cache' command as part of your production deployment routine. The command should not be run during local development as configuration options will frequently need to be changed during the course of your application's development.
8

Somewhat embarrassingly, I discovered another rather trivial cause for this error: I had a full stop in the filename of my blade file (eg resources/views/pages/user.invitation.blade.php). It really did make sense at the time!

I was trying to reference it like so: view('pages.user.invitation')

but of course Laravel was looking for the file at resources/views/pages/user/invitation.blade.php and throwing the view not found.

Hope this helps someone.

1 Comment

This was my exact issue.
4

Just in the controller call

return View('index');

without

::make

2 Comments

It appears that the OP is using Laravel 4 in which case the view helper does not exist. This won't work.
It works because you are using Laravel 5. As Jared said, the view helper didn't exist in Laravel 4.
3

I was having the same error, but in my case the view was called seeProposal.

I changed it to seeproposal and it worked fine...

It was not being an issue while testing locally, but apparently Laravel makes a distinction with capital letters running in production. So for those who have views with capital letters, I would change all of them to lowercase.

1 Comment

This was my issue. I used _incompleteCreditCheck. Although _sideMenu works fine. Changing it to _incompletecheck fixed it on the server. I am still baffled as to why the other works but not this single case.
2

In my case I was calling View::make('User/index'), where in fact my view was in user directory and it was called index.blade.php. Ergo after I changed it to View@make('user.index') all started working.

Comments

2

As @deanchiu said it may happen when you move the whole project to another path or server.

But in my case I had no access to command line on server and running following commands BEFORE I upload my project helped me.

> php artisan route:clear
> php artisan config:clear

Comments

1

check your blade syntax on the view that said not found i just fix mine

@if
@component
@endif 
@endcomponent

to

@if
@component
@endcomponent
@endif 

Comments

1

Use this on your cmd then run your project.

php artisan config:cache
php artisan route:cache
php artisan controller:cache
php artisan optimize:clear

1 Comment

I'm afraid php artisan controller:cache doesn't exist, at least not in current laravel version
0

Create the index.blade.php file in the views folder, that should be all

Comments

0

If your path to view is true first try to config:cache and route:cache if nothing changed check your resource path permission are true.

example: your can do it in ubuntu with :

sudo chgrp -R www-data resources/views
sudo usermod -a -G www-data $USER

Comments

0

I had the same error. I created a directory under views direcotry named users and created an index.blade.php file in it. When calling this file you should write users.index to indicate your path. Or just create index.blade.php file under views. hope this will help someone who gets the same problem

Comments

0

In addition to these answers, if your view is in an unusual directory for the project, you'll have to add the following to /config/view.php

    'paths' => [
    resource_path('views'),
    resource_path('../path/from/project/route/to/view')
],

Comments

0

If you are not accessing files as root user you shall change access of files

enter image description here

Change Access group to Access files

Also, others to Access files it's work for me

Comments

0

If you are using GIT in your project don't forget make git add . and commit before of move the project to another side and also don't forget clean the cache.

Comments

0

I'm using Laravel 10, in this time being, and I resolve this when renaming my index.blade.php into different file name such as home.blade.php

I tried using:

php artisan optimize:clear

Seems it doesn't work, so I renamed index.blade.php into home.blade.php

And on the controller

I replaced:

public function showIndex()
{
    return view('index');
}

Into:

public function showIndex()
{
    return view('home');
}

And inside the route on web.php: In my case it's:

Route::view('/', [HomeController::class, 'showIndex'])->name('home.index');

I hope this works as a solution to this error.

Comments

0

I did this on cpanel Server : after i uploaded index.blade.php , nothing changed So i compress the file (into zip format) then i uploaded on the place, extract it... and bam!

Comments

0

You can also try if all else failed to manually delete all files under:

bootstrap/cache 

Then running:
php artisan config:cache

Comments

-1

In my case, Laravel 5.3

Route::get('/', function(){
    return View('test');
});

test.blade.php was not rendering but some other views were rendering on localhost via XAMPP on mac. Upon running artisan server, the view started rendering for same url over XAMPP.

php artisan serve

To avoid any such scenario, one should test the Laravel apps with artisan server only.

Comments