简体   繁体   English

找不到Laravel 5.5特性

[英]Laravel 5.5 Trait not found

I can't wrap my head around this, as I have this on another project and works just fine. 我无法解决这个问题,因为我将其放在另一个项目上并且工作正常。 It is currently giving me this error 目前正在给我这个错误

Symfony \\ Component \\ Debug \\ Exception \\ FatalErrorException (E_UNKNOWN) Trait 'App\\Traits\\ResponseTrait' not found Symfony \\组件\\调试\\异常\\ FatalErrorException(E_UNKNOWN)未发现特性'App \\ Traits \\ ResponseTrait'

The UserRepository works just fine, the trait does not. UserRepository可以正常工作,特征不能正常工作。 I've tried renaming the trait, moving it to the repository folder, chmod it to 777, and I have no idea what could be wrong. 我尝试重命名该特征,将其移动到存储库文件夹,将其chmod更改为777,但我不知道有什么问题。

Meet my HomeController, the laravel's default: 满足我的HomeController,laravel的默认设置:

<?php
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Repositories\UserRepository as User;
use App\Traits\ResponseTrait;

class HomeController extends Controller
{
  use ResponseTrait;

  private $user;

  /**
  * Create a new controller instance.
  *
  * @return void
  */
  public function __construct(User $user)
  {
    $this->user = $user;
    $this->middleware('auth');
  }

  /**
  * Show the application dashboard.
  *
  * @return \Illuminate\Http\Response
  */
  public function index()
  {
    //dd($this->user->all()->toArray());
    //You can ignore the self:: part, as it doesn't reach this far.
    self::setData($this->user->all()->toArray());
    return "test";
    return view('home');
  }
}

The trait: 特质:

<?

namespace App\Traits;

trait ResponseTrait {
  public function setData($array) {

  }
}

The trait's path is /app/Traits/ResponseTrait.php 特质的路径是/app/Traits/ResponseTrait.php

At my composer.json, I've got PSR-4 autoload with the App directive. 在我的composer.json中,我使用App指令实现了PSR-4自动加载。

"psr-4": {
   "App\\": "app/"
}

Edit1: I have tried composer dump-autoload, issue remains Edit1:我尝试过作曲家转储自动加载,问题仍然存在

Don't use <? 不要使用<? , always use <?php . ,请始终使用<?php

Short open tags need to be enabled in php.ini and are not widely supported because they conflict with other languages. 短开放标记需要在php.ini中启用,并且由于与其他语言冲突而不受广泛支持。

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

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