I am querying data from database with two tables.
- Loads:
- LoadId
- OriginStopId
- DestStopId
- Stops:
- id
- City
- State
- loadId
A Load could have multiple stops but a stop has one load. A load has minimum two stops the origin and the destination.
I have created the models as
class LoadsModel extends Model
{
protected $table = 'loads';
public function stops(){
return $this->hasMany('App\Stops');
}
}
and
class Stops extends Model
{
protected $table = 'stops';
public function loads(){
return $this->belongsTo('App\LoadsModel');
}
}
I am using the model to pass the model into the view.
public function index()
{
$loads = LoadsModel::orderBy('loadId')->get();
return view('tender.available')->with(['loads'=>$loads]);
}
I want to show the result in a blade as according to the table headers where the Origin city is the origin city of the stop whose id is the same as the originstopId in loads table and Destination city of the stop whose id is the destStopId in loads table. I want to show the counts of the stops of a load. Something like this .
<table class="table">
<tr>
<th>Origin City</th>
<th>Origin State</th>
<th>Destination City</th>
<th>Destination State</th>
<th>Load Id</th>
<th>Stops</th>
</tr>
</table>