一對多的關係我有應與其他三個表,活動,捐贈&機會顯示所選專案編號的詳細信息,也該特定IDS DATAS刀片頁面。但我只能檢索項目表值而不是其他3個表。沒有錯誤信息。請幫助使用laravel查詢單個頁面中的所有4個表格。檢索值是在laravel
我ProjectController文件:
public function getDetailedProject()
{
$data=Project::all()->where('pid', 35);
$eve=Event::all()->where('pro_id', 35);
$don=Donation::all()->where('pro_id', 35);
$opp=Opportunity::all()->where('pro_id', 35);
return view('other.detailedProject')->with('data',$data);
}
我DetailedProject.blade.php文件代碼:
@extends('templates.default')
@section('content')
@foreach($data as $row)
<ul>
<h2>Project Details</h2>
<div class="row">
<div class="col-lg-3 col-md-3 col-sm-3">
<label>Project Title </label>
</div>
<div class="col-lg-9 col-md-9 col-sm-9">
<label> {{$row->ptitle}}</label>
</div>
</div>
<div class="row">
<div class="col-lg-3 col-md-3 col-sm-3">
<label>Project Description</label>
</div>
<div class="col-lg-9 col-md-9 col-sm-9">
<label> {{$row->pdescription}}</label>
</div>
</div>
<div class="row">
<div class="col-lg-3 col-md-3 col-sm-3">
<label>Project Duration</label>
</div>
<div class="col-lg-9 col-md-9 col-sm-9">
<label> {{$row->pduration}}</label>
</div>
</div>
<div class="row">
<div class="col-lg-3 col-md-3 col-sm-3">
<label>Project Start Date</label>
</div>
<div class="col-lg-9 col-md-9 col-sm-9">
<label> {{$row->psdate}}</label>
</div>
</div>
<div class="row">
<div class="col-lg-3 col-md-3 col-sm-3">
<label>Project End Date</label>
</div>
<div class="col-lg-9 col-md-9 col-sm-9">
<label> {{$row->pedate}}</label>
</div>
</div>
<div class="row">
<div class="col-lg-3 col-md-3 col-sm-3">
<label>Project Category</label>
</div>
<div class="col-lg-9 col-md-9 col-sm-9">
<label> {{$row->pcategory}} </label>
</div>
</div>
@endforeach
@foreach($data as $eve)
<h2>Event Details</h2>
<div class="row">
<div class="col-lg-3 col-md-3 col-sm-3">
<label>Event Title </label>
</div>
<div class="col-lg-9 col-md-9 col-sm-9">
<label> {{$eve->etitle}}</label>
</div>
</div>
<div class="row">
<div class="col-lg-3 col-md-3 col-sm-3">
<label>Event Details</label>
</div>
<div class="col-lg-9 col-md-9 col-sm-9">
<label> {{$eve->edetails}}</label>
</div>
</div>
<div class="row">
<div class="col-lg-3 col-md-3 col-sm-3">
<label>Event Date</label>
</div>
<div class="col-lg-9 col-md-9 col-sm-9">
<label> {{$eve->edate}}</label>
</div>
</div>
<div class="row">
<div class="col-lg-3 col-md-3 col-sm-3">
<label>Event Time</label>
</div>
<div class="col-lg-9 col-md-9 col-sm-9">
<label> {{$eve->etime}}</label>
</div>
</div>
<div class="row">
<div class="col-lg-3 col-md-3 col-sm-3">
<label>Project End Date</label>
</div>
<div class="col-lg-9 col-md-9 col-sm-9">
<label> {{$eve->elocation}}</label>
</div>
</div>
<div class="row">
<div class="col-lg-3 col-md-3 col-sm-3">
<label>Event Details</label>
</div>
<div class="col-lg-9 col-md-9 col-sm-9">
<label> {{$eve->eimage}}</label>
</div>
</div>
@endforeach
@foreach($data as $don)
<h2>Donation</h2>
<div class="row">
<div class="col-lg-3 col-md-3 col-sm-3">
<label>Total Cost</label>
</div>
<div class="col-lg-9 col-md-9 col-sm-9">
<label>{{$don->dtotal}}</label>
</div>
</div>
<div class="row">
<div class="col-lg-3 col-md-3 col-sm-3">
<label>Amount in Hand</label>
</div>
<div class="col-lg-9 col-md-9 col-sm-9">
<label> {{$don->dinhand}}</label>
</div>
</div>
<div class="row">
<div class="col-lg-3 col-md-3 col-sm-3">
<label>Amount Required</label>
</div>
<div class="col-lg-9 col-md-9 col-sm-9">
<label>{{$don->dtotal}} - {{$don->dinhand}}</label>
</div>
</div>
<div class="row">
<div class="col-lg-3 col-md-3 col-sm-3">
<label>Bank Account</label>
</div>
<div class="col-lg-9 col-md-9 col-sm-9">
<label> {{$don->dbankaccount}}</label>
</div>
</div>
@endforeach
@foreach($data as $opp)
<h2>Oppertunity</h2>
<div class="row">
<div class="col-lg-3 col-md-3 col-sm-3">
<label>Position</label>
</div>
<div class="col-lg-9 col-md-9 col-sm-9">
<label> {{$opp->oposition}}</label>
</div>
</div>
<div class="row">
<div class="col-lg-3 col-md-3 col-sm-3">
<label>Describtion</label>
</div>
<div class="col-lg-9 col-md-9 col-sm-9">
<label> {{$opp->odescription}}</label>
</div>
</div>
<div class="row">
<div class="col-lg-3 col-md-3 col-sm-3">
<label>Location</label>
</div>
<div class="col-lg-9 col-md-9 col-sm-9">
<label> {{$opp->olocation}}</label>
</div>
</div>
<div class="row">
<div class="col-lg-3 col-md-3 col-sm-3">
<label>Deadlinet</label>
</div>
<div class="col-lg-9 col-md-9 col-sm-9">
<label> {{$opp->odeadline}}</label>
</div>
</div>
@endforeach
</ul>
@stop
請幫我找出的錯誤。進出口新的laravel
您只將'$ data'傳遞到視圖中。 '$ eve','$ don'和'$ opp'不是'$ data'的一部分。你實際上從來沒有打過關係。 – aynber
不要使用'所有() - >其中()',這會從數據庫中的所有數據,然後過濾收集這是令人難以置信的低效率。使用'where() - > get()'來過濾數據庫,並只獲取符合條件的數據。 – Devon
我試過了,但仍然出現錯誤。那麼我應該如何編碼? –