I have two tables, orders and layers. In my orders table i save an array in layer_id which i have set it to varchar. I explode it first and i display the records. What i wanna do is to display the records from layers table , for example names from layer_name columns . I have also set their relationships . I would appreciate any suggestions.
My controller:
public function getCheckout(){
$orders = Order::get();
return View::make('checkout')->with('orders', $orders);
}
My view:
@forelse($orders as $order)
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">{{ $order->style_id }}</h3>
</div>
<div class="panel-body">
<p>Layers you chose</p>
<table class="table">
<tr>
<td>ID</td>
@foreach(explode(',', $order->layer_id) as $layer)
<td>{{ $layer }}</td>
@endforeach
</tr>
</table>
</div>
<div class="panel-footer"><button class="btn btn-primary">Confirm</button></div>
</div>
@empty
<p>Nothing to display</p>
@endforelse
My Model
Class Order extends Eloquent {
public function layer() {
return $this->belongsTo('Layer', 'layer_id');
}
}
See Question&Answers more detail:os