mercredi 22 janvier 2020

Getting data from pivotParent in Laravel

Currently i have 3 tables in MySQL(videos, keywords, video_keywords). video_keywords is a pivot form videos and keywords (id, keyword_id, video_id). The main question is: How to recieve data from pivotParent(name table from keywords table)? Currently i can only get keyword_id, video_id from video_keywords table and all data from videos table but i can't get anything from keywords table

Dump of $keyword->videos in keywords/list.blade.php is giving output:

[{"id":4,"youtube_id":"cq2Ef6rvL6g","title":"AMBIENT CHILLOUT LOUNGE RELAXING MUSIC - Essential Relax Session 1 - Background Chill Out Music -","created_at":"2020-01-22 14:39:41","updated_at":"2020-01-22 14:39:41","pivot":{"keyword_id":"5","video_id":"4"}}]

  #items: array:1 [▼
    0 => App\Models\Video {#390 ▼
      #fillable: array:2 [▶]
      #connection: "mysql"
      #table: "videos"
      #primaryKey: "id"
      #keyType: "int"
      +incrementing: true
      #with: []
      #withCount: []
      #perPage: 15
      +exists: true
      +wasRecentlyCreated: false
      #attributes: array:5 [▶]
      #original: array:7 [▶]
      #changes: []
      #casts: []
      #dates: []
      #dateFormat: null
      #appends: []
      #dispatchesEvents: []
      #observables: []
      #relations: array:1 [▼
        "pivot" => Illuminate\Database\Eloquent\Relations\Pivot {#391 ▼
          #guarded: []
          #connection: "mysql"
          #table: "video_keywords"
          #primaryKey: "id"
          #keyType: "int"
          +incrementing: true
          #with: []
          #withCount: []
          #perPage: 15
          +exists: true
          +wasRecentlyCreated: false
          #attributes: array:2 [▶]
          #original: array:2 [▶]
          #changes: []
          #casts: []
          #dates: []
          #dateFormat: null
          #appends: []
          #dispatchesEvents: []
          #observables: []
          #relations: []
          #touches: []
          +timestamps: false
          #hidden: []
          #visible: []
          #fillable: []
          +pivotParent: App\Models\Keyword {#356 ▼
            #fillable: array:1 [▶]
            #connection: "mysql"
            #table: "keywords"
            #primaryKey: "id"
            #keyType: "int"
            +incrementing: true
            #with: []
            #withCount: []
            #perPage: 15
            +exists: true
            +wasRecentlyCreated: false
            #attributes: array:4 [▼
              "id" => "5"
              "name" => "chill out music"
              "created_at" => "2020-01-22 14:40:52"
              "updated_at" => "2020-01-22 14:40:52"
            ]
            #original: array:4 [▶]
            #changes: []
            #casts: []
            #dates: []
            #dateFormat: null
            #appends: []
            #dispatchesEvents: []
            #observables: []
            #relations: array:1 [▶]
            #touches: []
            +timestamps: true
            #hidden: []
            #visible: []
            #guarded: array:1 [▶]
          }
          #foreignKey: "keyword_id"
          #relatedKey: "video_id"
        }
      ]
      #touches: []
      +timestamps: true
      #hidden: []
      #visible: []
      #guarded: array:1 [▶]
    }
  ]
}```


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire