Skip to content

Commit

Permalink
完成了用户个人中心相关
Browse files Browse the repository at this point in the history
  • Loading branch information
Administrator committed Mar 9, 2018
1 parent 4285a03 commit b6476a6
Show file tree
Hide file tree
Showing 24 changed files with 285 additions and 76 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/CommonController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function file_up()
//如果选择文件成功上传
$result['success'] = 1;
$result['message'] = '上传成功';
$result['url'] = $filepath;
$result['url'] = "$filepath";
}else{
//如果选择文件上传失败
$result['success'] = 0;
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class HomeController extends Controller
public function index()
{
$tops = Post::where('is_top','1')->take(2)->get();
$posts = Post::paginate(10);
$posts = Post::where('is_top','0')->paginate(10);
$categorys = Category::all();
return view('home.index.index',compact('tops','categorys','posts'));
}
Expand Down Expand Up @@ -73,7 +73,7 @@ public function reg()
public function logout()
{
Auth::logout();
return view('home.index.index');
return redirect('/');
}
}

Expand Down
14 changes: 13 additions & 1 deletion app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers;


use App\Model\Post;
use App\User;
use function React\Promise\all;

Expand Down Expand Up @@ -49,7 +50,7 @@ public function upload()
//TODO 判断当前的目录是否存在,若不存在就新建一个!
if (!is_dir($path)){mkdir($path,0777);}
$upload_result = move_uploaded_file($file_tmp, $file_path);
$avatar = $file_path;
$avatar = "/".$file_path;
//此函数只支持 HTTP POST 上传的文件
$status = User::where('id',\Auth::id())->update(compact('avatar'));
if ($upload_result && $status) {
Expand All @@ -62,6 +63,17 @@ public function upload()
}
return $this->showMsg($status, $message);
}
//用户中心
public function index()
{
$posts = Post::where('user_id',\Auth::id())->paginate(10);
return view('home.user.index',compact('posts'));
}
//我的主页
public function home()
{
return view('home.user.home');
}

function showMsg($status,$message = '',$data = array()){
$result = array(
Expand Down
1 change: 1 addition & 0 deletions app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,6 @@ class Kernel extends HttpKernel
'can' => \Illuminate\Auth\Middleware\Authorize::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'checkLogin' => \App\Http\Middleware\CheckLogin::class,
];
}
25 changes: 25 additions & 0 deletions app/Http/Middleware/CheckLogin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace App\Http\Middleware;

use Closure;
use Auth;

class CheckLogin
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if(auth()->check()){
return $next($request);

}
return redirect('/user/login')->withInput()->withErrors('请先登录');
}
}
4 changes: 2 additions & 2 deletions app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ class User extends Authenticatable
* 我的评论
*/
public function comments(){
return $this->hasMany('App\Model\Comment','user_id','id');
return $this->hasMany('App\Model\Comment','user_id','id')->orderBy('created_at','desc');
}

/**
* 我的帖子
*/
public function posts()
{
return $this->hasMany('App\Model\Post','post_id','id');
return $this->hasMany('App\Model\Post','user_id','id');
}

}
Expand Down
Binary file added public/upload/20180309/20180309160319.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/upload/20180309/20180309160507.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/upload/20180309/20180309160611.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/upload/20180309/20180309160704.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/upload/20180309/20180309160834.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/upload/20180309/20180309160922.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/upload/20180309/20180309161620.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/upload/20180309/20180309161942.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 4 additions & 7 deletions resources/views/home/index/index.blade.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
@extends('layouts.main')

@section('container')

@include('layouts.panel')
<div class="layui-container content">
<div class="layui-row layui-col-space15">
Expand All @@ -19,13 +18,11 @@
<img src="{{ $top->user->avatar }}" width="50px" height="50px" style="display: inline-block" alt="/{{ $top->user->name }}">
</a>
<h2>
<sapn>
<a class="layui-badge" style="{{ $top->category->tip_style }}">{{ $top->category->name }}</a>
</sapn>
<span class="layui-badge layui-bg-orange" style="top: -8px;border: none;">置顶</span>
<a href="/post/{{ $top->id }}">{{ $top->title }}</a>
</h2>
<div class="fly-list-info">
<a href="/post/{{ $top->id }}" link>
<a href="/post/{{ $top->id }}" >
<cite>{{ $top->user->name }}</cite>
</a>
<span>{{ $top->created_at->diffForHumans() }}</span>
Expand Down Expand Up @@ -60,12 +57,12 @@
</a>
<h2>
<sapn>
<a class="layui-badge" style="{{ $post->category->tip_style }}">{{ $post->category->name }}</a>
<a class="layui-badge" style="{{ $post->category->tip_style }};border: none;">{{ $post->category->name }}</a>
</sapn>
<a href="/post/{{ $post->id }}">{{ $post->title }}</a>
</h2>
<div class="fly-list-info">
<a href="user/home.html" link>
<a href="/user/home" link>
<cite>{{ $post->user->name }}</cite>
<!--
<i class="iconfont icon-renzheng" title="认证信息:XXX"></i>
Expand Down
10 changes: 10 additions & 0 deletions resources/views/home/index/login.blade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
@extends('layouts.main')

@section('container')
@if(count($errors) > 0)
@foreach($errors->all() as $error)
<script>
layer.msg('{{ $error }}', {
time: 1000
,shade: 0.2
});
</script>
@endforeach
@endif
<div class="layui-container fly-marginTop">
<div class="fly-panel fly-panel-user" pad20>
<div class="layui-tab layui-tab-brief" lay-filter="user">
Expand Down
16 changes: 13 additions & 3 deletions resources/views/home/post/detail.blade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
@extends('layouts.main')

@section('container')
<style>
#doc-content{
padding: 10px;
}
</style>
<div class="layui-container">
<div class="layui-row layui-col-space15">
<div class="layui-col-md8 content detail">
Expand All @@ -13,7 +18,7 @@
<!-- <span class="layui-badge" style="background-color: #5FB878;">已结</span> -->
<sapn><a class="layui-badge" style="{{ $post->category->tip_style }}">{{ $post->category->name }}</a></sapn>
@if($post->is_top == 1)
<span class="layui-badge layui-bg-black">置顶</span>
<span class="layui-badge layui-bg-orange">置顶</span>
@endif
@if($post->is_sticky == 1)
<span class="layui-badge layui-bg-red">精帖</span>
Expand Down Expand Up @@ -79,7 +84,7 @@
</div>
</div>
<div class="detail-body jieda-body photos">
<p>{!! $comment->content !!}</p>
{!! $comment->content !!}
</div>
<div class="jieda-reply">
@if($comment->zan(Auth::id())->exists())
Expand Down Expand Up @@ -164,7 +169,7 @@
var fm = document.getElementById('replyForm');
var fd = new FormData(fm);
fd.append('post_id',{{ $post->id }});
fd.append('user_id',{{ $post->user->id }});
fd.append('user_id',{{ Auth::id() }});
if($('#my-editormd-markdown-doc').val().length<5){
layer.msg('评论至少得5个字符', function(){
//关闭后的操作
Expand Down Expand Up @@ -259,4 +264,9 @@ function unzan(obj,id) {
}
</script>
<script>
$(function () {
$('a[href]').attr('target','_blank');
});
</script>
@endsection
87 changes: 87 additions & 0 deletions resources/views/home/user/home.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
@extends('layouts.main')
@section('container')
<div class="fly-home fly-panel" style="background-image: url();">
<img src="{{ Auth::user()->avatar }}" alt="贤心">
<i class="iconfont icon-renzheng" title="Fly社区认证"></i>
<h1>
{{ Auth::user()->name }}
<i class="iconfont @if(Auth::user()->sex == '') icon-nan @else icon-nv @endif"></i>
<!-- <i class="iconfont icon-nv"></i> -->
{{--<i class="layui-badge fly-badge-vip">VIP3</i>--}}
<!--
<span style="color:#c00;">(管理员)</span>
<span style="color:#5FB878;">(社区之光)</span>
<span>(该号已被封)</span>
-->
</h1>

{{--<p style="padding: 10px 0; color: #5FB878;">认证信息:layui 作者</p>--}}

<p class="fly-home-info">
<i class="iconfont icon-kiss" title="飞吻"></i><span style="color: #FF7200;">{{ Auth::user()->reward }} 飞吻</span>
<i class="iconfont icon-shijian"></i><span>{{ Auth::user()->created_at->toDateString() }} 加入</span>
<i class="iconfont icon-chengshi"></i><span>来自{{ Auth::user()->city }}</span>
</p>

<p class="fly-home-sign">({!! Auth::user()->sign !!})</p>

<div class="fly-sns" data-user="">
<a href="javascript:;" class="layui-btn layui-btn-primary fly-imActive" data-type="addFriend">加为好友</a>
<a href="javascript:;" class="layui-btn layui-btn-normal fly-imActive" data-type="chat">发起会话</a>
</div>

</div>

<div class="layui-container">
<div class="layui-row layui-col-space15">
<div class="layui-col-md6 fly-home-jie">
<div class="fly-panel">
<h3 class="fly-panel-title">{{ Auth::user()->name }} 最近的提问</h3>
<ul class="jie-row">
@if(Auth::user()->posts()->count())
@foreach(Auth::user()->posts as $post)
<li>
@if($post->is_top == 1)
<span class="layui-badge layui-bg-orange">置顶</span>
@endif
@if($post->is_sticky == 1)
<span class="layui-badge layui-bg-red">精</span>
@endif
<span class="layui-badge" style="{{ $post->category->tip_style }}">{{ $post->category->name }}</span>
<a href="" class="jie-title"> {{ $post->title }}</a>
<i>{{ $post->created_at->diffForHumans() }}</i>
<em class="layui-hide-xs">{{ $post->renqi }}阅/{{ $post->comments->count() }}答</em>
</li>
@endforeach
@else
<div class="fly-none" style="min-height: 50px; padding:30px 0; height:auto;"><i style="font-size:14px;">没有发表任何求解</i></div>
@endif
</ul>
</div>
</div>

<div class="layui-col-md6 fly-home-da">
<div class="fly-panel">
<h3 class="fly-panel-title">{{ Auth::user()->name }} 最近的回答</h3>
<ul class="home-jieda">
@if(Auth::user()->comments->count())
@foreach(Auth::user()->comments as $comment)
<li>
<p>
<span>{{ $comment->created_at->diffForHumans() }}</span>
在<a href="/post/{{$comment->post->id}}" target="_blank">{{ $comment->post->title }}</a>中回答:
</p>
<div class="home-dacontent">
{!! $comment->content !!}
</div>
</li>
@endforeach
@else
<div class="fly-none" style="min-height: 50px; padding:30px 0; height:auto;"><span>没有回答任何问题</span></div>
@endif
</ul>
</div>
</div>
</div>
</div>
@endsection
50 changes: 50 additions & 0 deletions resources/views/home/user/index.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
@extends('layouts.main')

@section('container')
<style>
.post-list{
padding:0 10px;
}
</style>
<div class="layui-container fly-marginTop fly-user-main">
@include('home.user.main')

<div class="fly-panel fly-panel-user">
<!--
<div class="fly-msg" style="margin-top: 15px;">
您的邮箱尚未验证,这比较影响您的帐号安全,<a href="activate.html">立即去激活?</a>
</div>
-->
<div class="layui-tab layui-tab-brief" lay-filter="user">
<ul class="layui-tab-title" id="LAY_mine">
<li data-type="mine-jie" lay-id="index" class="layui-this">我发的帖(<span>{{ Auth::user()->posts->count() }}</span>)</li>
<li data-type="collection" data-url="/collection/find/" lay-id="collection">我收藏的帖(<span>16</span>)</li>
</ul>
<div class="layui-tab-content" style="padding: 20px 0;">
<div class="layui-tab-item layui-show">
<ul class="mine-view jie-row">
@foreach($posts as $post)
<li class="post-list">
<a class="jie-title" style="" href="/post/{{ $post->id }}" target="_blank">{{ $post->title }}</a>
<i>{{ $post->created_at->diffForHumans() }}</i>
<a class="mine-edit" href="#">编辑</a>
<em>{{ $post->renqi }}阅/{{ $post->comments->count() }}答</em>
</li>
@endforeach
</ul>
<div id="LAY_page"></div>
</div>
<div class="layui-tab-item">
<ul class="mine-view jie-row">
<li>
<a class="jie-title" href="../jie/detail.html" target="_blank">基于 layui 的极简社区页面模版</a>
<i>收藏于23小时前</i> </li>
</ul>
<div id="LAY_page1"></div>
</div>
</div>
</div>
</div>
</div>

@endsection
Loading

0 comments on commit b6476a6

Please sign in to comment.