Skip to content

Commit

Permalink
用户话题列表
Browse files Browse the repository at this point in the history
  • Loading branch information
summerblue committed Mar 6, 2022
1 parent 94af965 commit cece852
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 12 deletions.
6 changes: 6 additions & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,10 @@ class User extends Authenticatable implements MustVerifyEmail
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 @@ -32,11 +32,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 class="text-decoration-none" 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>
24 changes: 15 additions & 9 deletions resources/views/users/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
<div class="col-lg-3 col-md-3 hidden-sm hidden-xs user-info">
<div class="card ">
<img class="card-img-top" src="{{ $user->avatar }}" alt="{{ $user->name }}">
<div class="card-body">
<h5><strong>个人简介</strong></h5>
<p>{{ $user->introduction }}</p>
<hr>
<h5><strong>注册于</strong></h5>
<p>{{ $user->created_at->diffForHumans() }}</p>
</div>
<div class="card-body">
<h5><strong>个人简介</strong></h5>
<p>{{ $user->introduction }}</p>
<hr>
<h5><strong>注册于</strong></h5>
<p>{{ $user->created_at->diffForHumans() }}</p>
</div>
</div>
</div>
<div class="col-lg-9 col-md-9 col-sm-12 col-xs-12">
Expand All @@ -27,9 +27,15 @@
<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 cece852

Please sign in to comment.