Skip to content

Commit

Permalink
用户话题列表
Browse files Browse the repository at this point in the history
  • Loading branch information
summerblue committed Sep 20, 2019
1 parent 8d25b82 commit e2ffb2e
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 5 deletions.
5 changes: 5 additions & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@ class User extends Authenticatable implements MustVerifyEmailContract
protected $casts = [
'email_verified_at' => 'datetime',
];

public function topics()
{
return $this->hasMany(Topic::class);
}
}
13 changes: 10 additions & 3 deletions resources/views/layouts/_header.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,18 @@
{{ Auth::user()->name }}
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="{{ route('users.show', Auth::id()) }}">个人中心</a>
<a class="dropdown-item" href="{{ route('users.edit', Auth::id()) }}">编辑资料</a>
<a class="dropdown-item" href="{{ route('users.show', Auth::id()) }}">
<i class="far fa-user mr-2"></i>
个人中心
</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="{{ route('users.edit', Auth::id()) }}">
<i class="far fa-edit mr-2"></i>
编辑资料
</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" id="logout" href="#">
<form action="{{ route('logout') }}" method="POST">
<form action="{{ route('logout') }}" method="POST" onsubmit="return confirm('您确定要退出吗?');">
{{ csrf_field() }}
<button class="btn btn-block btn-danger" type="submit" name="button">退出</button>
</form>
Expand Down
25 changes: 25 additions & 0 deletions resources/views/users/_topics.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@if (count($topics))

<ul class="list-group mt-4 border-0">
@foreach ($topics as $topic)
<li class="list-group-item pl-2 pr-2 border-right-0 border-left-0 @if($loop->first) border-top-0 @endif">
<a href="{{ route('topics.show', $topic->id) }}">
{{ $topic->title }}
</a>
<span class="meta float-right text-secondary">
{{ $topic->reply_count }} 回复
<span> ⋅ </span>
{{ $topic->created_at->diffForHumans() }}
</span>
</li>
@endforeach
</ul>

@else
<div class="empty-block">暂无数据 ~_~ </div>
@endif

{{-- 分页 --}}
<div class="mt-4 pt-1">
{!! $topics->render() !!}
</div>
8 changes: 6 additions & 2 deletions resources/views/users/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@
<hr>

{{-- 用户发布的内容 --}}
<div class="card ">
<div class="card">
<div class="card-body">
暂无数据 ~_~
<ul class="nav nav-tabs">
<li class="nav-item"><a class="nav-link active bg-transparent" href="#">Ta 的话题</a></li>
<li class="nav-item"><a class="nav-link" href="#">Ta 的回复</a></li>
</ul>
@include('users._topics', ['topics' => $user->topics()->recent()->paginate(5)])
</div>
</div>

Expand Down

0 comments on commit e2ffb2e

Please sign in to comment.