简体   繁体   English

“目标 [App\\Http\\Controllers\\Controller] 不可实例化。”

[英]"Target [App\Http\Controllers\Controller] is not instantiable."

I'm trying to follow laracasts tutorial on laravel fundamentals but after getting composer and laravel installed with no problems I can't get my routes file to work with the controller I've reinstalled laravel copied it exactly how laracasts has his but still nothing, anyone see anything wrong with these two files?我正在尝试按照 laracasts 教程学习 laravel 基础知识,但是在安装了 composer 和 laravel 后没有任何问题,我无法让我的路由文件与控制器一起使用有人看到这两个文件有什么问题吗?

routes.php files route.php 文件

<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/

Route::get('/', 'Controller@index');
Route::get('contact', 'Controller@contact');

controller.php file控制器.php文件

<?php

namespace App\Http\Controllers;

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

abstract class Controller extends BaseController
{
    use DispatchesJobs, ValidatesRequests;

    public function ___construct()
    {
        $this->middleware('guest');
    }

    public function index()
    {
        return 'hello world!';
    }

    public function contact()
    {
     return 'Contact me!';
    }
}

I have it hosted on localhost:8888 using phps server command if that is any help.如果有帮助,我使用 phps 服务器命令将它托管在 localhost:8888 上。

The reason might be that your controller class is abstract, hence it's not instantiable. 原因可能是您的控制器类是抽象的,因此它不可实例化。 Remove the abstract keyword. 删除abstract关键字。

如果您的路线是 get 或 post 并且实际上您已经实现了资源,那么您会收到此类错误

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 目标不可实例化。 Laravel 5 - 应用绑定服务提供者 - Target is not instantiable. Laravel 5 - App binding service provider 目标接口不可实例化。 Laravel 4 - Target Interface is not instantiable. Laravel 4 Laravel “目标 [Illuminate\\Contracts\\Bus\\Dispatcher] 不可实例化。” - Laravel "Target [Illuminate\Contracts\Bus\Dispatcher] is not instantiable." 尝试更新用户时,无法实例化目标[App \\ Http \\ Requests \\ Request] - Target [App\Http\Requests\Request] is not instantiable when trying to update user 构建 [Controller] 时目标 [Interface] 不可实例化 - Target [Interface] is not instantiable while building [Controller] Illuminate\Routing\Controller 或 App\Http\Controllers\Controller - Illuminate\Routing\Controller or App\Http\Controllers\Controller Laravel 6 控制器错误 - 目标类 [App\\Http\\Controllers\\TestContoller] 不存在 - Laravel 6 Controller Error - Target class [App\Http\Controllers\TestContoller] does not exist Controller 已导入但 web.php 抛出目标 class [App\Http\Controllers\Auth\LoginController] 不存在 - Controller is imported but web.php throws Target class [App\Http\Controllers\Auth\LoginController] does not exist 目标 [App\\Interfaces\\IPostRepository] ​​在构建时不可实例化 - Target [App\Interfaces\IPostRepository] is not instantiable while building 找不到 Laravel 类“App\\Http\\Controllers\\Controller” - Laravel Class 'App\Http\Controllers\Controller' not found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM