Hi I have Order, Order_items, Customer and Product in my application
order migration and relatioship
Schema::create('orders', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id');
$table->string('status');
$table->timestamps();
});
public function customer()
{
return $this->hasOne('App\Customer','id');
}
customer
Schema::create('customers', function (Blueprint $table) {
$table->increments('id');
$table->string('firstname');
$table->string('lastname');
$table->string('street');
$table->string('city');
$table->string('psc');
$table->string('email');
$table->string('phone');
$table->timestamps();
});
order_items
Schema::create('order_items', function (Blueprint $table) {
$table->increments('id');
$table->integer('order_id');
$table->integer('product_id');
$table->integer('quantity');
$table->decimal('price',10,2);
$table->timestamps();
});
public function product()
{
return $this->hasOne('App\Product','id');
}
}
and Product
Schema::create('products', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->text('description');
$table->string('slug')->unique;
$table->decimal('price',10,2);
$table->timestamps();
});
in administartion I have controller for one order detailas, where i need to dispaly customer information, order_items with product name
public function detail($id)
{
$order = Order::find($id);
return view('admin.detail', ['order' => $order]);
}
and view
@extends('layouts.admin')
@section('content')
<div class="row">
{{ $order->customer->firstname }}
</div>
<ul>
@foreach ($order->items as $item)
<li>{{ $item->product->name }}</li>
@endforeach
</ul>
@stop
but this is not function, where is my mistake to work with relationship