找不到Laravel类'App \ Http \ Controllers \ Controller'

时间:2019-12-08 13:37:07

标签: php laravel

我是Laravel的新手,正在尝试修复此错误。 Controller.php存在于App\Http\Controllers\中。我已经尝试过作曲家dump-autoload,它没有解决它。

我已阅读到我需要使用工匠为我的应用命名。然后它将名称空间从App \更改为我的应用名称。我应该这样做吗?

<?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.';
}
}

3 个答案:

答案 0 :(得分:1)

尝试一次composer dump-autoload命令。

编辑:删除此行class HomeController extends Controller

并将其替换为class HomeController extends \App\Http\Controllers\Controller

OR

class HomeController extends App\Http\Controllers\Controller

答案 1 :(得分:0)

use App\Http\Controllers\Controller;无需将其卸下,您的控制器应该可以正常工作。

答案 2 :(得分:0)

如果App / Http / Controllers /文件夹中没有Controller.php文件,也会发生错误。

确保文件存在。