2017-10-11 70 views
0

一對多的關係我有應與其他三個表,活動,捐贈&機會顯示所選專案編號的詳細信息,也該特定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

+1

您只將'$ data'傳遞到視圖中。 '$ eve','$ don'和'$ opp'不是'$ data'的一部分。你實際上從來沒有打過關係。 – aynber

+0

不要使用'所有() - >其中()',這會從數據庫中的所有數據,然後過濾收集這是令人難以置信的低效率。使用'where() - > get()'來過濾數據庫,並只獲取符合條件的數據。 – Devon

+0

我試過了,但仍然出現錯誤。那麼我應該如何編碼? –

回答

0

試試這個代碼,希望工程!

$data=Project::where('pid', 35)->get(); 
$eve=Event::where('pro_id', 35)->get(); 
$don=Donation::where('pro_id', 35)->get(); 
$opp=Opportunity::where('pro_id', 35)->get(); 
return view('other.detailedProject', compact('data', 'eve', 'don', 'opp')); 
+0

我試過了,但收到了錯誤信息。 「未定義的常量數據的使用 - 假設 '數據'(查看:C:\ XAMPP \ htdocs中\博客\資源\意見\其它\ detailedProject.blade.php)」。這個。如何解決它? –