简体   繁体   中英

Laravel Class 'App\Http\Controllers\Controller' not found

I am new to Laravel and I am trying to fix this error. Controller.php exists in App\\Http\\Controllers\\ . I have tried composer dump-autoload and it did not fix it.

I have read that I would need to use artisan to give name to my app. Then it would change namespace from App\\ to my app name. 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.

Edit : Remove this line class HomeController extends Controller

and replace it with 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; take it off, your controller should be working fine.

Error can also occur if App/Http/Controllers/ folder does not have Controller.php file.

Make sure file exists.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM