[英]Laravel Class 'App\Http\Controllers\Controller' not found
I am new to Laravel and I am trying to fix this error.我是 Laravel 的新手,我正在尝试修复此错误。 Controller.php exists in
App\\Http\\Controllers\\
. Controller.php 存在于
App\\Http\\Controllers\\
。 I have tried composer dump-autoload and it did not fix it.我试过 composer dump-autoload 但它没有修复它。
I have read that I would need to use artisan to give name to my app.我已经读到我需要使用 artisan 来命名我的应用程序。 Then it would change namespace from App\\ to my app name.
然后它将命名空间从 App\\ 更改为我的应用程序名称。 Should I do that?
我应该这样做吗?
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Html\FormBuilder;
use DB;
use App\Http\Controllers\Controller;
class HomeController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
}
/**
* Show the application dashboard.
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function index()
{
return view('home');
}
public function insertform()
{
return view('home');
}
public function insertMeasurement(Request $request) {
$neck = $request->input('neck');
$arm_length = $request->input('arm_length');
$chest = $request->input('chest');
$stomach = $request->input('stomach');
$seat = $request->input('seat');
$shirt_length = $request->input('shirt_length');
$shoulder = $request->input('shoulder');
$arm = $request->input('arm');
$bicep = $request->input('bicep');
$wrist = $request->input('wrist');
$data=array("neck"=>$neck,"arm_length"=>$arm_length,"chest"=>$chest,"stomach"=>$stomach,"seat"=>$seat,
"shirt_length"=>$shirt_length,"shoulder"=>$shoulder,"arm"=>$arm,"bicep"=>$bicep,"wrist"=>$wrist);
DB::table('measurements')->insert($data);
echo "Record inserted successfully.<br/>";
echo '<a href = "/insert">Click Here</a> to go back.';
}
}
Try composer dump-autoload
command once.尝试一次
composer dump-autoload
命令。
Edit : Remove this line class HomeController extends Controller
编辑:删除这一行
class HomeController extends Controller
and replace it with class HomeController extends \\App\\Http\\Controllers\\Controller
并将其替换为
class HomeController extends \\App\\Http\\Controllers\\Controller
OR或者
class HomeController extends App\\Http\\Controllers\\Controller
there is no need for this use App\\Http\\Controllers\\Controller;
不需要这个
use App\\Http\\Controllers\\Controller;
take it off, your controller should be working fine.取下它,您的控制器应该可以正常工作。
Error can also occur if App/Http/Controllers/ folder does not have Controller.php file.如果 App/Http/Controllers/ 文件夹没有 Controller.php 文件,也会发生错误。
Make sure file exists.确保文件存在。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.