我想在表格用戶中獲得用戶名,在帖子表中發帖ID並返回View::make('post.index')
。我需要在post.index刀片中查看。需要幫助laravel 4.2
Database
users table
id
username
post table
id
message
posts_id
Post.php @models folder
public function posts()
{
return $this->belongsTo('User');
}
User.php @models folder
public function post()
{
return $this->hasMany('Post');
}
PostController.php @controller folder
public function index()
{
$posts = Post::with('username')->get();
return View::make('post.index')->with('posts', $posts);
}
post/index.blade.php
the result here
i need to the result of author id become the username
道歉,但你所寫的內容非常模糊, 。你能否編輯一下,以便更清楚地解決你想解決的問題? – rayryeng 2014-08-31 05:05:42
嗨rayryeng謝謝我更新帖子需要幫助,讓author_id獲取用戶表中的用戶名 – btn25 2014-08-31 05:21:19
好的,這有點更好。我希望有人能夠幫助你。祝你好運! – rayryeng 2014-08-31 05:23:50