Hi, I have two models :
Sale.php <?php
class Sale extends Eloquent {
public function groups() {
return $this->hasMany('Group');
}
Group.php
class Group extends Eloquent{
public function categories() {
return $this->hasMany('Categorie');
}
public function items() {
return $this->hasMany('Item');
}
public function sale() {
return $this->belongsTo('Sale');
}
}
the two tables sales and group are created in database, and there is a column sale_id in groups.
But when i use $sale->groups(), there is no value return (it's empty). The object $sale is correct, it has all its attributes set.
Someone have an idea?
dd($sale->groups->toArray());
Does that result in an empty array too?
Yes, i have the good result. But i want to get all the objects "group", and with this code, i get only the attributes into an array...
Remove ->toArray()
then.
The difference is basically ->groups()
and ->groups
. One is the collection/model, the other is the data. I think it's the data you want. Unfiltered, so no ->toJson()
or ->toArray()
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community