So i have two tables, Bids table and Projects table. Relationship between them as such:
Bids.php:
public function projects()
{
return $this->belongsTo('App\Projects');
}
Projects.php:
public function bids()
{
return $this->hasMany('App\Bids');
}
This is Projects table. This is Bids table. I want to print all the bid data along with their respective projects data in each row of table in View. I tried to do this way in my controller:
$bids= auth()->user()->bids()->get();
foreach($bids as $bid)
{
$projects= Projects::find($bid->project_id);
}
return view('bids.index',compact('bids','projects'));
index view:
@if($bids->count() != 0)
@foreach($bids as $bid)
<tr>
<td><a href="{{ route('projects.select',$projects->id) }}">{{$projects->name}}</a></td>
<td>{{$bid->status}}</td>
</tr>
@endforeach
@else
<tr>
<td colspan="6" class="text-center">No record found.</td>
</tr>
@endif
But I got the data repeated in one row of table. So what should be the proper way to do it? Sorry if this is a bit vague, but this is my best way to explain it in abstract.