可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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 you@example.com 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
回答1:
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.
回答2:
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
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.
回答3:
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
回答4:
Just in the controller call return View('index');
without ::make
回答5:
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.
回答6:
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.
回答7:
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