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
The UserRepository works just fine, the trait does not. 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.
Meet my HomeController, the laravel's default:
<?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
At my composer.json, I've got PSR-4 autoload with the App directive.
"psr-4": {
"App\\": "app/"
}
Edit1: I have tried composer dump-autoload, issue remains
<?, always use<?php.