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

afoysal's avatar

Display 2 types of data

I have 2 types of user Athletes and Teams. I created 3 tables users,athletes & teams. I am storing username & password in users table and others information in athletes & teams table. I would like to display Athletes and Teams information in home page.

My User model is like below

<?php

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $guarded = [];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = ['password', 'remember_token',];
    
    protected $fillable = ['email','password','remember_token','category_id'];

    public function team()
    {
        return $this->hasOne(Team::class);
    }

    public function athlete()
    {
        return $this->hasOne(Athlete::class);
    }
}

My Team model is like below

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Team extends Model
{    
  public $guarded = [];

  protected $fillable = ['first_name','last_name','user_id','how_did_find','social_media',];

  public function user()
  {
    return $this->belongsTo(User::class);
  }
}

My Athlete model is like below

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Athlete extends Model
{    
  public $guarded = [];

  protected $fillable = ['user_id','social_media','youtube_video','website'];

  public function user()
  {
    return $this->belongsTo(User::class);
  }
}

I am using below code in controller.

$staff_picks = User::orderBy('id','desc')->take(10)->with('category','athlete','team')->get();
0 likes
3 replies
bobbybouwmann's avatar

I still can't really help you. What data do you want to show on the homepage?

You have all the information send to your view already, just loop over it and display it on the page ;)

Please or to participate in this conversation.