I have three tables : "Users", "tickets" and "events". I want to get tickets of the users and the details of tickets is in events. I want to get data from all table using relationships.
i need user and ticket of user and event of that ticket
Also am i doing it properly?
I have made relations with all the tables.
table structure is:
users
-username, user_id
ticket_orders
-user_id , ticket_id, event_id
events
-event_id, event_name
For Users
    public function ticketOrder(){
        return $this->hasMany('App\TicketOrder', 'user_id', 'user_id');
    }
For tickets
public function user(){
       return $this->belongsTo('App\User', 'user_id', 'user_id');
   }
   public function events(){
       return $this->belongsTo('App\Event', 'event_id', 'event_id');
   }
for events
 public function ticketOrder(){
        return $this->hasMany('App\TicketOrder', 'event_id', 'event_id');
    }
I tried this in controller
here CreateEvent and Event is same. On my code i am using "CreateEvent" instead of "Event"
public function showMyTickets()
    {
        $user = Auth::user();
        $ticket= $user->with('TicketOrder','TicketOrder.CreateEvents')->where('user_id',$user->user_id)->get();
        dd($ticket);
    }
this is what i got in dd($ticket) the data are in relations. now i dont know how to retrive it and am i doing it correctly.
Collection {#1164 ▼
  #items: array:1 [▼
    0 => User {#970 ▼
      #fillable: array:6 [▶]
      #hidden: array:3 [▶]
      #casts: array:1 [▶]
      #connection: "mysql"
      #table: "users"
      #primaryKey: "id"
      #keyType: "int"
      +incrementing: true
      #with: []
      #withCount: []
      #perPage: 15
      +exists: true
      +wasRecentlyCreated: false
      #attributes: array:11 [▶]
      #original: array:11 [▶]
      #changes: []
      #dates: []
      #dateFormat: null
      #appends: []
      #dispatchesEvents: []
      #observables: []
      #relations: array:1 [▼
        "TicketOrder" => Collection {#1163 ▼
          #items: array:1 [▼
            0 => TicketOrder {#1068 ▼
              #fillable: array:8 [▶]
              #hidden: array:8 [▶]
              #connection: "mysql"
              #table: "ticket_orders"
              #primaryKey: "id"
              #keyType: "int"
              +incrementing: true
              #with: []
              #withCount: []
              #perPage: 15
              +exists: true
              +wasRecentlyCreated: false
              #attributes: array:11 [▶]
              #original: array:11 [▶]
              #changes: []
              #casts: []
              #dates: []
              #dateFormat: null
              #appends: []
              #dispatchesEvents: []
              #observables: []
              #relations: array:1 [▼
                "CreateEvents" => CreateEvent {#1155 ▼
                  #fillable: array:22 [▶]
                  #hidden: array:1 [▶]
                  #connection: "mysql"
                  #table: "create_events"
                  #primaryKey: "id"
                  #keyType: "int"
                  +incrementing: true
                  #with: []
                  #withCount: []
                  #perPage: 15
                  +exists: true
                  +wasRecentlyCreated: false
                  #attributes: array:26 [▶]
                  #original: array:26 [▶]
                  #changes: []
                  #casts: []
                  #dates: []
                  #dateFormat: null
                  #appends: []
                  #dispatchesEvents: []
                  #observables: []
                  #relations: []
                  #touches: []
                  +timestamps: true
                  #visible: []
                  #guarded: array:1 [▶]
                }
              ]
              #touches: []
              +timestamps: true
              #visible: []
              #guarded: array:1 [▶]
            }
          ]
        }
      ]
      #touches: []
      +timestamps: true
      #visible: []
      #guarded: array:1 [▶]
      #rememberTokenName: "remember_token"
    }
  ]
}
