0

初めてEloquentを使用し、ここで何が問題なのか理解できません..

class TourItem extends Eloquent {
    public function tour()
    {
        return $this->belongsTo('Tour');
    }
}

class Tour extends Eloquent {   
    public function tourItem()
    {
        return $this->hasMany('TourItem');
    }
}

ここでは、ツアー項目を取得しようとしていますが、NULL のみを返します。

    $tour = Tour::where('slug', '=', $postSlug)->where('wrh_id', '=', 1)->first();
    if (!is_null($tour)) {

        var_dump($tour->tourItem);

        foreach ($tour->tourItem as $item) {
            var_dump($item->texto);
        }
    }

DB スキーマ:

    Schema::create('tours', function($t) {
                $t->increments('id');
                $t->string('titulo');
                $t->string('slug');
                $t->boolean('main');
                $t->integer('wrh_id');
                $t->timestamps();
            });

    Schema::create('tour_items', function($t) {
                $t->increments('id');
                $t->string('titulo');
                $t->text('texto');
                $t->text('saiba_mais');
                $t->integer('tour_id');
                $t->timestamps();
            });

エラーはどこですか??

ありがとうロベルト

4

1 に答える 1

1

編集

私はあなたの移行とモデルをテストし、何も触れずにすべて動作します。あなたの質問に答えるgithubでレポを作成します。

Roberto でうまくいかなかった理由はわかりませんが、データベースまたは移行の設定を間違えている可能性があります。

リポジトリのコードがお役に立てば幸いです。Readme の指示に従ってください。

于 2013-05-21T01:10:45.103 に答える