は、私が選択し、作成したフォームに取り組んできたが、インデックスブレードが正しく表示されない「市場」と「屋台」Laravel関係の復帰は結果
と関係を持っている「予約」を持っていません。
それは、「ID」を取得し、
<td>{{$user->role ? $user->role->name : 'User has no role'}}</td>
以下のように「名前」フィールドに変換し、これは、次の機種コードで正しく表示されるはずです:{)
を パブリック関数の役割(return $this->belongsTo('App\Role');
}
、これが私の "予約" のモデルである:FOで
public function marketdate(){
return $this->belongsTo('App\Markets');
}
public function stallstype() {
return $this->belongsTo('App\Stalls');
}
index.blade上llowing:
...
<td>{{$booking->marketdate ? $booking->marketdate->date : '-' }}</td>
<td>{{$booking->stallstype ? $booking->stallstype->name : '-'}}</td>
...
しかし、これは単に示して「を - 」それはページをレンダリングするときに、データベースに格納されている
IDさんが正しいとそれだけで正しく表示されない相関ん。
ストールテーブルを::次のように
もうひとつ、テーブルスキーマがある
Schema::create('stalls', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->integer('cost');
$table->timestamps();
});
市場テーブル:
Schema::create('markets', function (Blueprint $table) {
$table->increments('id');
$table->string('date');
$table->integer('is_active');
$table->timestamps();
});
エラーは次のとおりです。
at PhpEngine- >evaluatePath('C:\xampp\htdocs\moowoos\storage\framework\views/3bcb71b43fffee7f9 a9edf18bfb397ab94380507.php', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'bookings' => object(Collection), 'markets' => array('Saturday 4th March', 'Saturday 5th April', 'Saturday 6th May', 'Saturday 7th June', 'Saturday 8th July', 'Saturday 8th July'), 'stalltype' => array('Preloved', 'Craft', 'Business'))) in compiled.php line 15361
at CompilerEngine->get('C:\xampp\htdocs\moowoos\resources\views/admin/bookings/index.blade.php', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'bookings' => object(Collection), 'markets' => array('Saturday 4th March', 'Saturday 5th April', 'Saturday 6th May', 'Saturday 7th June', 'Saturday 8th July', 'Saturday 8th July'), 'stalltype' => array('Preloved', 'Craft', 'Business'))) in compiled.php line 15193
それはそれが配列を返す
です:
あなたが関連するモデルをロードしたい場合は、外部キー列がリスト()メソッドに渡されていることを確認し
? – ggdxはい、まあ、私はDB内の "予約"テーブル内のIDを見ることができ、それらのIDは、関連ページの私のドロップダウンは、同じ関係を使用して入力すると、関連テーブルのDBに対応します – Luke
私は、あなたが予約のためのデータを取得していないと言うと、結果では常にfalseです。 $予約オブジェクトをどのように取得しますか? – boroboris