How can I get the parent without children with child's eloquent model?
Child eloquent:
class ProductColor extends Model
{
protected $table = 'product_color';
public function product()
{
return $this->belongsTo(Product::class);
}
}
parent eloquent:
class Product extends Model
{
public function colors()
{
return $this->hasMany(ProductColor::class);
}
}
$productColor = ProductColor::find(1);
$product = $productColor->product;
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community