Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel-RouteCollection.php中的NotFoundHttpException-除/route显示错误外的所有页面_Php_Laravel - Fatal编程技术网

Laravel-RouteCollection.php中的NotFoundHttpException-除/route显示错误外的所有页面

Laravel-RouteCollection.php中的NotFoundHttpException-除/route显示错误外的所有页面,php,laravel,Php,Laravel,我面临的错误似乎很常见。但我在网上的各种帖子上找到的解决方案似乎并没有解决我的问题 我是Laravel的新手,并已使用 最初的设置似乎运行良好,我的route()页面运行正常。但是,我添加到routes.php或web.php文件中的任何其他路由似乎都不起作用。我在RouteCollection.php行xyz中收到一个错误,它是NotFoundHttpException My web.php文件: <?php //works Route::get('/', function () {

我面临的错误似乎很常见。但我在网上的各种帖子上找到的解决方案似乎并没有解决我的问题

我是Laravel的新手,并已使用

最初的设置似乎运行良好,我的route()页面运行正常。但是,我添加到routes.php或web.php文件中的任何其他路由似乎都不起作用。我在RouteCollection.php行xyz中收到一个错误,它是NotFoundHttpException

My web.php文件:

<?php

//works
Route::get('/', function () {
    return view('welcome');
});

//does not work
Route::get('/hello',function(){
    return "welcome";
});

//does not work
//Route::get('hello', 'Hello@index');

//does not work
/*Route::get('hello',function(){
    return view('welcome');
});*/

任何帮助都将不胜感激。我被卡住了

我认为您设置web服务器的方式并不完全正确。web服务器应指向
公用
文件夹。然后,您可以不使用
public
URI访问它

使用您提供的信息,如果将其指向公用文件夹,则无需使用
public
URL即可访问这些信息:

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

http://localhost/laravel/larashop/


Route::get('/hello',function() { return 'Something'; })

http://localhost/laravel/larashop/hello
如果您坚持将web服务器指向根项目文件夹,该文件夹将在路由中包含公共URI(强烈不推荐),则您可以按如下方式访问路由:

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

http://localhost/laravel/larashop/public/


Route::get('/hello',function() { return 'Something'; })

http://localhost/laravel/larashop/public/hello

我认为您设置web服务器的方式并不完全正确。web服务器应指向
公用
文件夹。然后,您可以不使用
public
URI访问它

使用您提供的信息,如果将其指向公用文件夹,则无需使用
public
URL即可访问这些信息:

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

http://localhost/laravel/larashop/


Route::get('/hello',function() { return 'Something'; })

http://localhost/laravel/larashop/hello
如果您坚持将web服务器指向根项目文件夹,该文件夹将在路由中包含公共URI(强烈不推荐),则您可以按如下方式访问路由:

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

http://localhost/laravel/larashop/public/


Route::get('/hello',function() { return 'Something'; })

http://localhost/laravel/larashop/public/hello

按照Demonyowh和geckob的建议,使用
php artisan serve
,解决了我的问题!谢谢大家!

按照Demonyowh和geckob的建议,使用
php artisan serve
,解决了我的问题!谢谢大家!

试试这个为什么不使用
php artisan Service
呢?谢谢!工作!那么,我是否应该尝试在index.php的代码中使用链接,比如表单提交等?或者我需要做一些设置更改,这样我就不需要index.php了。。。正如我所提到的,这个链接是有效的,但是添加任何进一步的内容都只适用于index.php。试试这个为什么不使用
php artisan Service
呢?谢谢!工作!那么,我是否应该尝试在index.php的代码中使用链接,比如表单提交等?或者我需要做一些设置更改,这样我就不需要index.php了。。。正如我所提到的,这个链接是有效的,但是添加任何进一步的内容都只能使用index.php。这是一个测试项目,我写这个项目是为了学习Laravel。一旦我编写了实际的项目代码,我肯定会将web服务器指向公用文件夹。但是,我希望这不会导致错误?@user7983103php artisan serve如果您只是在测试,您实际上可以运行php artisan serve作为快速web服务器如果您认为这是答案,请随意投票并接受这一答案:)@user7983103php artisan serve为我的本地用户解决了问题。这将把问题缩小到我设置服务器的范围。那么,当我运行用于生产的代码时,如何确保我不会面临同样的问题呢?我不能在那里使用php artisan服务?如果你将你的web服务器指向公共目录,它将像php artisan服务一样工作。这是我为学习Laravel而编写的一个测试项目。一旦我编写了实际的项目代码,我肯定会将web服务器指向公用文件夹。但是,我希望这不会导致错误?@user7983103php artisan serve如果您只是在测试,您实际上可以运行php artisan serve作为快速web服务器如果您认为这是答案,请随意投票并接受这一答案:)@user7983103php artisan serve为我的本地用户解决了问题。这将把问题缩小到我设置服务器的范围。那么,当我运行用于生产的代码时,如何确保我不会面临同样的问题呢?我不能在那里使用php artisan服务?如果您将您的web服务器指向公共目录,它将像php artisan服务一样工作