I'm trying to get data from pivot table and passing them with jquery ajax. I want to get the name of the book and the quantity of its.
My Model
class Order extends Model
{
public function books(){
return $this->belongsToMany(Book::class)->withPivot('quantity');
}
}
class Book extends Model
{
public function order(){
return $this->belongsToMany(Order::class)->withPivot('quantity');
}
}
This is my controller
public function detail($id){
if($id){
$order = Order::find($id);
dd($order->books);
}
}
I dont know why it returned
Illuminate\Database\Eloquent\Collection {#350 ▼
#items: []
}
Aucun commentaire:
Enregistrer un commentaire