laravel load relationship hasmany code example
Example 1: laravel update or create wioth hasmany relation
class Item extends Model
{
protected $fillable = ['menu_id', 'parent_id', 'title', 'order', 'resource_link', 'html_class', 'is_blank'];
public function translations()
{
return $this->hasMany(MenuItemTranslation::class, 'menu_item_id');
}
}
Example 2: laravel load relation on a relation
$books = Book::with('author.contacts')->get();