在测试Laravel 5时,我似乎遇到了一些名称空间问题。我尝试了几种组合,但这是我认为应该有效的组合(根据我的理解)。希望我能得到一些帮助 - 我想了解我的错误,理想情况下不仅仅是修改代码:)
UsersController.php
<?php namespace App\Http\Controllers;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\User;
use AllStars\Transformers\UserTransformer;
class UsersController extends Controller {
protected $userTransformer;
function __construct(UserTransformer $userTransformer)
{
$this->userTransformer = $userTransformer;
}
Transformer.php
<?php namespace AllStars\Transformers;
abstract class Transformer {
public function transformCollection(array $items)
{
return array_map([$this, 'transform'], $items);
}
public abstract function transform($item);
}
UserTransformer.php
<?php namespace AllStars\Transformers;
class UserTransformer extends Transformer {
private function transform($user)
{
return [
'id' => $user['id'],
'name' => $user['name'],
'email' => $user['email'],
];
}
}
当我使用UsersController时,出现以下错误:
Container.php第833行中的ReflectionException:Class AllStars \ Transformers \ UserTransformer不存在
需要提供任何其他信息,请告诉我们!