added a relationship between User, and Posts

This commit is contained in:
Ghostie 2024-08-21 10:01:15 -05:00
parent dff18be098
commit 3deef3707e
2 changed files with 14 additions and 0 deletions

View File

@ -15,4 +15,13 @@ class Post extends Model
"image",
"user_id"
];
public function user()
{
return $this->belongsTo(User::class)->select([
"id",
"name",
"username"
]);
}
}

View File

@ -45,4 +45,9 @@ class User extends Authenticatable
'password' => 'hashed',
];
}
public function posts()
{
return $this->hasMany(Post::class);
}
}