自动加载文件laravel 4失败

问题描述:

我需要快速帮助。 自动加载时我的类,它抛出我一个错误:自动加载文件laravel 4失败

Class 'Applicant\Respository\ApplicantInterface' does not exist 

我曾尝试和查找有关自动载入的一些文章,包括fideloper example但仍没有运气。这里是我的代码:

树结构

resultchecker 
    +app 
    +Applicant 
    +Helper 
    +Provider 
    +Repository 
     +Eloquent 
     -Applicant.php 
    -ApplicantInterface.php 

ApplicantInterface.php

namespace Applicant\Repository; 

interface ApplicantInterface { 
    public function all(); 
    public function get(); 
    public function lookup(); 
} 

HomeController.php

use Applicant\Respository\ApplicantInterface; 

class HomeController extends BaseController { 

    public function __construct(ApplicantInterface $applicantRepo) 
    { 
     $this->applicantRepo = $applicantRepo; 
    } 

    public function home() 
    { 
     return View::make('app.index'); 
    } 

composer.json

"autoload": { 
     "classmap": [ 
      "app/commands", 
      "app/controllers", 
      "app/models", 
      "app/database/migrations", 
      "app/database/seeds", 
      "app/tests/TestCase.php" 
     ], 
     "files" : [ 
     "app/Applicant/Helper/functions.php" 
     ], 
     "psr-0" : { 
      "Applicant" : "app/" 
     } 
    }, 

我在这里做错了什么?

看起来你ApplicantInterface.php不在Repository目录,所以你要移动它,使您的结构看起来像如下:

resultchecker 
    -app 
    -Applicant 
    -Helper 
    -Provider 
    -Repository 
     -Eloquent 
     Applicant.php 
     ApplicantInterface.php 

如果它不能正常工作,请尝试运行php artisan dump-autoload

我也建议您切换从psr-0psr-4自动加载:

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

祝你好运!