2014-11-07 2 views
-1

양식에서 수집하려고하는 데이터의 모델을 인식하지 못하는 곳에서 작성한 Eloquent Repository에 문제가 있습니다. 내 모델을 Eloquent Repository의 네임 스페이스에 복사 했는데도 여전히 인식되지 않습니다.Laravel PHP : Eloquent Repository가 모델을 인식하지 못합니다.

웅변 저장소 (응용 프로그램 \ 한국 전기 \ 저장소 \ 웅변 \ EloquentVideoRepository.php) :

<?php namespace Acme\repositories\Eloquent; 

use acme\repositories\VideoRepository; 

/* Tried copying the 'Video' model into the same 
    namespace as this Eloquent Repository but it is not being recognized. */ 

use acme\repositories\Video; 

class EloquentVideoRepository implements VideoRepository { 

    public function all() 
    { 
     return Video::all(); 
    } 

    /* This function below generates an error since the 'Video' class 
    is not found from my 'Video' Model */ 

    public function create($input) 
    { 
    return Video::create($input); 
    } 
} 

모델 (응용 프로그램 \ 모델 Video.php을 \) :

<?php 

/* Original Line of code below that generated the error: 

class Video extends Eloquent 
*/ 

/* EDIT: I put a backslash in front of Eloquent 
and now the model is recognized. 
*/ 
class Video extends \Eloquent { 

/** 
* The table used by this model 
* 
* @var string 
**/ 
protected $table = 'videos'; 

/** 
* The primary key 
* 
* @var string 
**/ 
protected $primaryKey = 'video_id'; 

/** 
* The fields that are guarded cannot be mass assigned 
* 
* @var array 
**/ 
protected $guarded = array(); 

/** 
* Enabling soft deleting 
* 
* @var boolean 
**/ 
protected $softDelete = true; 

} 

I 위의 모델을 'app \ acme \ repositories'에 복사했습니다. 표시

오류 메시지 : 심지어이 네임 스페이스에 모델을 복사 한 후 PHP 장인 덤프 - 자동로드를 수행하려고했지만 여전히 작동하지 않습니다

'Class acme\repositories\Video not found' 

. 어떤 도움을 주셔서 감사합니다.

+0

이름과 네임 스페이스 plz를 포함하여 Video 클래스 파일의 헤드를 표시합니다. 정확한 오류 메시지도 표시하십시오. – ToBe

+0

위의 편집을 참조하십시오. –

답변

1

Video 클래스 파일에 네임 스페이스 선언이 없으므로 기본 네임 스페이스에 있습니다. 뭔가를 확장해도 네임 스페이스가 바뀌지 않습니다.

이 원하는 공간 itno 추가 상단에이 줄을 추가

namespace Acme\repositories\Eloquent; 

을 또는 다른 파일에 다음과 같이 사용 라인을 추가 할 수 있지만 은 그게 당신이 원하는 의심 :

use \Video; 
+0

귀하의 제안을 사용했지만 모델을 인식하지 못했습니다. 나는 몇 가지 실험을 시도하고 계속 게시 할 것입니다. –

+0

Ok 해결책을 찾았습니다. 그것은 2 가지를 조합 한 것입니다 : 1) 위에서 언급 한 것처럼 네임 스페이스를 사용하십시오. 2) 원래 'Video.php'모델 클래스는 '클래스 비디오가 Eloquent로 확장되었습니다.'라고 정의되었으므로 'Eloquent'앞에 백 슬래시를 넣고 이제는 Eloquent Repository가 모델을 인식합니다. 도와 줘서 고마워! –

+0

ToBe, 위의 편집을 참조하십시오. –

관련 문제