eagerloadingproblem

PHP

No description

Guest

Download Edit

<?php
$offers = Car::with(array('Bids' => function($query){
$query->orderBy('gebot', 'ASC');
}))->get();
return $offers;
?>
RETURNS:
[
{
id: 13,
user_id: 11,
buyer_id: 12,
ends_at: "2014-10-18 16:03:00",
meet_at: "2014-10-31 16:03:00",
active: 1,
status: 3,
created_at: "2014-10-17 16:04:41",
updated_at: "2014-10-17 17:16:58",
bids: [
{
id: 9,
user_id: 12,
car_id: 13,
gebot: 15000,
created_at: "-0001-11-30 00:00:00",
updated_at: "-0001-11-30 00:00:00"
},
{
id: 7,
user_id: 12,
car_id: 13,
gebot: 25000,
created_at: "2014-10-17 16:05:29",
updated_at: "2014-10-17 16:05:29"
},
{
id: 8,
user_id: 12,
car_id: 13,
gebot: 25000,
created_at: "2014-10-17 17:11:15",
updated_at: "2014-10-17 17:11:15"
}
]
},
{
id: 14,
user_id: 11,
buyer_id: 0,
ends_at: "2014-10-17 17:03:00",
meet_at: "2014-10-31 17:03:00",
active: 1,
status: 1,
created_at: "2014-10-17 17:03:37",
updated_at: "2014-10-17 17:03:44",
bids: [ ]
},
{
id: 15,
user_id: 11,
buyer_id: 0,
ends_at: "2014-10-24 17:08:00",
meet_at: "2014-10-31 17:08:00",
active: 1,
status: 1,
created_at: "2014-10-17 17:08:29",
updated_at: "2014-10-17 17:10:44",
bids: [ ]
}
]
<?php
$offers = Car::with(array('Bids' => function($query){
$query->orderBy('gebot', 'ASC');
}))->get();
return $offers[0];
?>
RETURNS:
{
id: 13,
user_id: 11,
buyer_id: 12,
ends_at: "2014-10-18 16:03:00",
meet_at: "2014-10-31 16:03:00",
active: 1,
status: 3,
created_at: "2014-10-17 16:04:41",
updated_at: "2014-10-17 17:16:58",
bids: [
{
id: 9,
user_id: 12,
car_id: 13,
gebot: 15000,
created_at: "-0001-11-30 00:00:00",
updated_at: "-0001-11-30 00:00:00"
},
{
id: 7,
user_id: 12,
car_id: 13,
gebot: 25000,
created_at: "2014-10-17 16:05:29",
updated_at: "2014-10-17 16:05:29"
},
{
id: 8,
user_id: 12,
car_id: 13,
gebot: 25000,
created_at: "2014-10-17 17:11:15",
updated_at: "2014-10-17 17:11:15"
}
]
}
<?php
$offers = Car::with(array('Bids' => function($query){
$query->orderBy('gebot', 'ASC');
}))->get();
return $offers[0]['bids'];
?>
RETURNS:
[
{
id: 7,
user_id: 12,
car_id: 13,
gebot: 25000,
created_at: "2014-10-17 16:05:29",
updated_at: "2014-10-17 16:05:29"
},
{
id: 8,
user_id: 12,
car_id: 13,
gebot: 25000,
created_at: "2014-10-17 17:11:15",
updated_at: "2014-10-17 17:11:15"
},
{
id: 9,
user_id: 12,
car_id: 13,
gebot: 15000,
created_at: "-0001-11-30 00:00:00",
updated_at: "-0001-11-30 00:00:00"
}
]
Why is orderBy('gebot', 'ASC') not working anymore here?
Second Question:
<?php
$offers = Car::with(array('Bids' => function($query){
$query->orderBy('gebot', 'ASC');
}))->get();
return $offers;
?>
How can I only return $offers that have at least 1 "Bid" from "Bids"?
Is there a chance to do this with eloquent?