无法在laravel 5.4上找到“Class'App \ Http \ Controllers \ Controller'找不到”

时间:2018-04-06 12:35:31

标签: laravel class controller routes

我的laravel项目存在问题 目前我一直在工作的注册页面,但它没有找到类控制器 enter image description here

这是我的路线脚本

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

Route::get('/signin', function() {
    return view('login');
});

Route::get('/register', function() {
    return view('register.register');
});

Route::post('/register_action','RegisterController@store');

RegisterController脚本

<?php

namespace App\Http\Controllers;
//use App\RegisterController;


use Illuminate\Http\Request;

class RegisterController extends Controller
{
    //

    public function store(){
        echo "test";
    }
}

并查看注册刀片

@extends('layout');

@section('content')

<h2>Vertical (basic) form</h2>
  <form action="/register_action" method="post">

    <input type="hidden" name="_token" value="{{csrf_token()}}">

    <div class="form-group">
      <label for="name">Name:</label>
      <input type="name" name="username" class="form-control" id="name" placeholder="Enter Name">
    </div>
    <div class="form-group">
      <label for="email">Email:</label>
      <input type="email" name="email" class="form-control" id="email" placeholder="Enter email">
    </div>
    <div class="form-group">
      <label for="pwd">Password:</label>
      <input type="password" name="password" class="form-control" id="pwd" placeholder="Enter password">
    </div>
     <div class="form-group">
      <label for="pwd"Confirm >Password:</label>
      <input type="password" name="cpassword" class="form-control" id="pwd" placeholder="Confirm password">
    </div>
    <div class="checkbox">
      <label><input type="checkbox" name="remember"> Remember me</label>
    </div>
    <button type="submit" class="btn btn-default">Submit</button>
  </form>

@endsection

3 个答案:

答案 0 :(得分:1)

检查项目中是否存在Http/Controllers/Controller.php

如果没有,只需创建它,复制粘贴此代码并保存:

<?php

namespace App\Http\Controllers;

use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;

class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
}

让我知道它是否有效!

答案 1 :(得分:0)

你应该试试这个:

<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class RegisterController extends Controller
{
    //

    public function store(){
        echo "test";
    }
}

答案 2 :(得分:0)

大家好,你需要将下面一行代码写入你的

protected $namespace = 'App\Http\Controllers';

app\providers\RouteServiceProvider.php file.
 
 

然后你可以访问控制器到 web.php 文件