Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

garrettmassey's avatar

Issue of 'Duplicate key "hasMany" detected' while using LaravelShift Blueprint

I have started a new project (using Laravel 6.2 because it is the version we use at work for now) to learn LaravelShift Blueprint (you can also find the Laracast video here). I have created my draft.yaml file and things seem to work just fine until I add specific relationships.

models:
      Properties:
        users_id: id foreign:users.id
        properties_name: string
        properties_description: longtext nullable
        relationships:
          belongsTo: Users
          hasMany: Rooms
      Rooms:
        users_id: id foreign:users.id
        properties_id: id foreign:properties.id
        rooms_name: string
        rooms_description: longtext nullable
        relationships:
          belongsTo: Properties
          hasMany: Items
      Categories:
        users_id: id foreign:users.id
        categories_name: string
        categories_description: longtext nullable
        relationships:
          belongsTo: Users
      Items:
        users_id: id foreign:users.id
        properties_id: id foreign:properties.id
        rooms_id: id foreign:rooms.id
        items_name: string
        items_description: longtext nullable
        items_make: string nullable
        items_model: string nullable
        purchased_from: string nullable
        categories_id: id nullable
        items_count: integer nullable
        items_cost: decimal:11,2 nullable
        items_value: decimal:11,2 nullable
        items_condition: string nullable
        items_serial_num: string nullable
        items_barcode: string nullable
        relationships:
          belongsTo: Users
          hasOne: Categories
          hasMany: Images
          hasMany: Notes
          belongsToMany: Tags
      Tags:
        users_id: id foreign:users.id
        tags_name: string
        tags_description: longtext nullable
        relationships:
          belongsTo: Users
      ItemsTags:
        users_id: id foreign:users.id
        items_id: id foreign:items.id
        tags_id: id foreign:tags.id
      Images:
        users_id: id foreign:users.id
        items_id: id foreign:items.id
        images_name: string
        images_description: longtext nullable
        images_slug: string
        images_url: string
        relationships:
          belongsTo: Items
      Notes:
        users_id: id foreign:users.id
        items_id: id foreign:items.id
        notes_name: string
        notes_description: longtext
        relationships:
          belongsTo: Items

This is my .yaml file, and when I run php artisan blueprint:build I get this error:

Symfony\Component\Yaml\Exception\ParseException  : Duplicate key "hasMany" detected at line 43 (near "hasMany: Notes:notes.items_id").

I am not sure why that isn't allowed. In this instance, an Item can have many Notes and many Images. it's how the database is set up, and Eloquent should allow for this anyway. I haven't been able to find any mention of this in the Blueprint docs, so I was wondering if it is an issue with Blueprint or an issue with how I am declaring my relationships in the .yaml file?

Thank you for your help!

0 likes
1 reply
Roman-S's avatar

Instead this

hasMany: Images
hasMany: Notes

use this

hasMany: Images, Notes
2 likes

Please or to participate in this conversation.