0
我有一個「預訂」具有與「市場」和「攤位」Laravel關係沒有返回結果
我已在選擇工作創建表單上,但該指數刀片顯示不正確的關係。
應該採取「ID」,並在下面的
<td>{{$user->role ? $user->role->name : 'User has no role'}}</td>
轉換爲「姓名」字段作爲這與下面的型號代碼正確顯示: 公共職能作用(){
return $this->belongsTo('App\Role');
}
,這是我的 「預訂」 模式:
public function marketdate(){
return $this->belongsTo('App\Markets');
}
public function stallstype() {
return $this->belongsTo('App\Stalls');
}
隨着FO在index.blade llowing:
...
<td>{{$booking->marketdate ? $booking->marketdate->date : '-' }}</td>
<td>{{$booking->stallstype ? $booking->stallstype->name : '-'}}</td>
...
但是,這只是顯示「 - 」,當它呈現在網頁
標識的存儲在數據庫中是正確的,並做相關這是不正確顯示。其他
一兩件事,表架構如下:
攤位表:
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
是的,我可以在數據庫的「預訂」表中看到ID,並且這些ID與相關表的數據庫中的內容相對應,因爲我在創建頁面上的下拉列表使用相同的關係來填充 – Luke
I' d說你沒有得到任何預訂數據,並且結果總是錯誤的。你如何獲取你的$預訂對象? – boroboris