我已根据下面创建了一个控制器文件并为其创建路由。我想通过输入以下URL在我的网站上显示Hello World消息: http://localhost/mylaravel/mycontroller但它显示了404错误。
控制器文件:
namespace App\Http\Controllers;
class MyController extends BaseController
{
public function loadview()
{
echo "Hello World";
}
}
路由文件:
Route::get('/', function ()
{
return view('welcome');
});
Route::get('mycontroller','MyController@loadview');
答案 0 :(得分:1)
您的 Web服务器很可能配置错误,并且Laravel应用程序未运行。很容易检查,只需在 index.php 中添加 die(),看看你是否仍然获得404 - 如果仍然有404错误,那么请求尚未达到Laravel应用程序。
确保 http://localhost/mylaravel 指向Laravel应用程序的公共文件夹。
答案 1 :(得分:0)
If you have not configured http://localhost/mylaravel
to point to the public
folder in your project folder (mylaravel
), then first try including public
in the url: http://localhost/mylaravel/public
If the problem persists, you have to check if your server runs at all, and whether other sites on your localhost
are fine. Go to http://localhost/
in your browser to confirm. This should load an index page for your server. If http://localhost/
returns 404
or some other error, then your server may be offline or needing attention.