我有一个简单的laravel 4应用程序,它有3个MySql表:quote,quote_tag和tag。 我正在尝试使用Eloquent为特定报价添加标记。一旦我使用新标签提交表单,我的商店功能似乎无法创建关联实体Eloquent模型,Quote_Tag,并返回错误消息:
" Class' Quote_Tag'找不到"
我在这里做错了什么?
Routes.php:
Route::get('/{idQuote}/tag', 'TagController@create');
Route::post('/{idQuote}/tag', 'TagController@store');
TagController.php:
public function create($idQuote)
{
$quote = Quote::find($idQuote);
return View::make('tags.create')->with('quote', $quote);
}
public function store($idPersona, $idQuote)
{
$tag = new Tag;
$tag->tagText = Input::get('tagText');
$tag->save();
$quote_tag = new Quote_Tag;
$quote_tag->idTag = $tag->idTag;
$quote_tag->idQuote = $idQuote;
$quote_tag->save();
$tags = Tag::all();
$quote_tags = Quote_Tag::all();
return View::make('tags.index')->with('tags', $tags)->with('quote_tags', $quote_tags);
}
视图/标签/ create.blade.php:
{{ Form::open([ 'url' => '{/{idQuote}/tag']) }}
{{ Form::label('tagText', 'Tag Text: ') }}
{{ Form::text('tagText') }}
{{ Form::label('idQuote', 'Quote ID: ') }}
{{ Form::text('idQuote', $quote->idQuote) }}
{{ Form::submit('Submit Tag') }}</div>
{{ Form::close() }}
视图/标签/ index.blade.php:
@foreach($tags as $tag)
<li>{{ $tag }}</li>
@endforeach
@foreach($quote_tags as $quote_tag)
<li>{{ $quote_tag }}</li>
@endforeach
模型/ Quote.php:
class Quote extends Eloquent {
public $timestamps = false;
protected $table = 'quote';
protected $primaryKey = 'idQuote';
public function tags()
{
return $this->belongsToMany('Tag', 'quote_tag', 'idQuote', 'idTag');
}
}
模型/ Quote_Tag.php:
class Quote_Tag extends Eloquent {
public $timestamps = false;
protected $table = 'quote_tag';
protected $primaryKey = 'idQuote_Tag';
public function quote()
{
return $this->hasOne('Quote', 'idQuote');
}
public function tag()
{
return $this->hasOne('Tag', 'idTag');
}
}
模型/ Tag.php:
class Tag extends Eloquent {
public $timestamps = false;
protected $table = 'tag';
protected $primaryKey = 'idTag';
public function quotes()
{
return $this->belongsToMany('Quote', 'quote_tag', 'idQuote', 'idTag');
}
}
MySQL表:
CREATE TABLE `mountain`.`quote` (
`idQuote` INT NOT NULL AUTO_INCREMENT,
`quoteText` TEXT NOT NULL,
`quoteSource1` VARCHAR(100) NULL,
`quoteSource2` VARCHAR(100) NULL,
`idPersona` INT NULL,
PRIMARY KEY (`idQuote`),
CREATE TABLE `mountain`.`tag` (
`idTag` INT NOT NULL AUTO_INCREMENT,
`tagText` VARCHAR(45) NOT NULL,
PRIMARY KEY (`idTag`));
CREATE TABLE `mountain`.`quote_tag` (
`idQuote_Tag` INT NOT NULL AUTO_INCREMENT,
`idQuote` INT NOT NULL,
`idTag` INT NOT NULL,
PRIMARY KEY (`idQuote_Tag`),
INDEX `idTag_idx` (`idTag` ASC),
INDEX `idQuote_idx` (`idQuote` ASC),
CONSTRAINT `idTag`
FOREIGN KEY (`idTag`)
REFERENCES `mountain`.`tag` (`idTag`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `idQuote`
FOREIGN KEY (`idQuote`)
REFERENCES `mountain`.`quote` (`idQuote`)
ON DELETE NO ACTION
ON UPDATE NO ACTION);
答案 0 :(得分:0)
@thesingularity
做一个
composer dump-autoload -o
因为您的错误消息显示&#34; Class&#39; Quote_Tag&#39;找不到&#34;并且你的声明看起来是正确的。