diff --git a/app/Http/Controllers/CommonController.php b/app/Http/Controllers/CommonController.php index c9205b9..7d808bc 100644 --- a/app/Http/Controllers/CommonController.php +++ b/app/Http/Controllers/CommonController.php @@ -26,7 +26,7 @@ public function file_up() //如果选择文件成功上传 $result['success'] = 1; $result['message'] = '上传成功'; - $result['url'] = $filepath; + $result['url'] = "$filepath"; }else{ //如果选择文件上传失败 $result['success'] = 0; diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 44e3820..74d2a80 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -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')); } @@ -73,7 +73,7 @@ public function reg() public function logout() { Auth::logout(); - return view('home.index.index'); + return redirect('/'); } } diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index f3dbc7e..8b3eeac 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers; +use App\Model\Post; use App\User; use function React\Promise\all; @@ -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) { @@ -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( diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index 93bf68b..1ae6d26 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -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, ]; } diff --git a/app/Http/Middleware/CheckLogin.php b/app/Http/Middleware/CheckLogin.php new file mode 100644 index 0000000..9e715fe --- /dev/null +++ b/app/Http/Middleware/CheckLogin.php @@ -0,0 +1,25 @@ +check()){ + return $next($request); + + } + return redirect('/user/login')->withInput()->withErrors('请先登录'); + } +} diff --git a/app/User.php b/app/User.php index 2ac4e01..8d2e6db 100644 --- a/app/User.php +++ b/app/User.php @@ -17,7 +17,7 @@ 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'); } /** @@ -25,7 +25,7 @@ public function comments(){ */ public function posts() { - return $this->hasMany('App\Model\Post','post_id','id'); + return $this->hasMany('App\Model\Post','user_id','id'); } } diff --git a/public/upload/20180309/20180309160319.jpg b/public/upload/20180309/20180309160319.jpg new file mode 100644 index 0000000..4235a91 Binary files /dev/null and b/public/upload/20180309/20180309160319.jpg differ diff --git a/public/upload/20180309/20180309160507.jpg b/public/upload/20180309/20180309160507.jpg new file mode 100644 index 0000000..4235a91 Binary files /dev/null and b/public/upload/20180309/20180309160507.jpg differ diff --git a/public/upload/20180309/20180309160611.jpg b/public/upload/20180309/20180309160611.jpg new file mode 100644 index 0000000..4235a91 Binary files /dev/null and b/public/upload/20180309/20180309160611.jpg differ diff --git a/public/upload/20180309/20180309160704.jpg b/public/upload/20180309/20180309160704.jpg new file mode 100644 index 0000000..4235a91 Binary files /dev/null and b/public/upload/20180309/20180309160704.jpg differ diff --git a/public/upload/20180309/20180309160834.jpg b/public/upload/20180309/20180309160834.jpg new file mode 100644 index 0000000..4235a91 Binary files /dev/null and b/public/upload/20180309/20180309160834.jpg differ diff --git a/public/upload/20180309/20180309160922.jpg b/public/upload/20180309/20180309160922.jpg new file mode 100644 index 0000000..4235a91 Binary files /dev/null and b/public/upload/20180309/20180309160922.jpg differ diff --git a/public/upload/20180309/20180309161620.jpg b/public/upload/20180309/20180309161620.jpg new file mode 100644 index 0000000..4235a91 Binary files /dev/null and b/public/upload/20180309/20180309161620.jpg differ diff --git a/public/upload/20180309/20180309161942.jpg b/public/upload/20180309/20180309161942.jpg new file mode 100644 index 0000000..4235a91 Binary files /dev/null and b/public/upload/20180309/20180309161942.jpg differ diff --git a/resources/views/home/index/index.blade.php b/resources/views/home/index/index.blade.php index 133f0ad..50b33ae 100644 --- a/resources/views/home/index/index.blade.php +++ b/resources/views/home/index/index.blade.php @@ -1,7 +1,6 @@ @extends('layouts.main') @section('container') - @include('layouts.panel')
@@ -19,13 +18,11 @@ /{{ $top->user->name }}

- - {{ $top->category->name }} - + 置顶 {{ $top->title }}

- + {{ $top->user->name }} {{ $top->created_at->diffForHumans() }} @@ -60,12 +57,12 @@

- {{ $post->category->name }} + {{ $post->category->name }} {{ $post->title }}

- + {{ $post->user->name }} {{ $post->category->name }} @if($post->is_top == 1) - 置顶 + 置顶 @endif @if($post->is_sticky == 1) 精帖 @@ -79,7 +84,7 @@
-

{!! $comment->content !!}

+ {!! $comment->content !!}
@if($comment->zan(Auth::id())->exists()) @@ -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(){ //关闭后的操作 @@ -259,4 +264,9 @@ function unzan(obj,id) { } + @endsection \ No newline at end of file diff --git a/resources/views/home/user/home.blade.php b/resources/views/home/user/home.blade.php new file mode 100644 index 0000000..f079b2e --- /dev/null +++ b/resources/views/home/user/home.blade.php @@ -0,0 +1,87 @@ +@extends('layouts.main') +@section('container') +
+ 贤心 + +

+ {{ Auth::user()->name }} + + + {{--VIP3--}} + +

+ + {{--

认证信息:layui 作者

--}} + +

+ {{ Auth::user()->reward }} 飞吻 + {{ Auth::user()->created_at->toDateString() }} 加入 + 来自{{ Auth::user()->city }} +

+ +

({!! Auth::user()->sign !!})

+ + + +
+ +
+
+
+
+

{{ Auth::user()->name }} 最近的提问

+
    + @if(Auth::user()->posts()->count()) + @foreach(Auth::user()->posts as $post) +
  • + @if($post->is_top == 1) + 置顶 + @endif + @if($post->is_sticky == 1) + + @endif + {{ $post->category->name }} + {{ $post->title }} + {{ $post->created_at->diffForHumans() }} + {{ $post->renqi }}阅/{{ $post->comments->count() }}答 +
  • + @endforeach + @else +
    没有发表任何求解
    + @endif +
+
+
+ +
+
+

{{ Auth::user()->name }} 最近的回答

+
    + @if(Auth::user()->comments->count()) + @foreach(Auth::user()->comments as $comment) +
  • +

    + {{ $comment->created_at->diffForHumans() }} + 在{{ $comment->post->title }}中回答: +

    +
    + {!! $comment->content !!} +
    +
  • + @endforeach + @else +
    没有回答任何问题
    + @endif +
+
+
+
+
+@endsection \ No newline at end of file diff --git a/resources/views/home/user/index.blade.php b/resources/views/home/user/index.blade.php new file mode 100644 index 0000000..5377c62 --- /dev/null +++ b/resources/views/home/user/index.blade.php @@ -0,0 +1,50 @@ +@extends('layouts.main') + +@section('container') + +
+ @include('home.user.main') + +
+ +
+
    +
  • 我发的帖({{ Auth::user()->posts->count() }}
  • +
  • 我收藏的帖(16
  • +
+
+
+
    + @foreach($posts as $post) +
  • + {{ $post->title }} + {{ $post->created_at->diffForHumans() }} + 编辑 + {{ $post->renqi }}阅/{{ $post->comments->count() }}答 +
  • + @endforeach +
+
+
+
+ +
+
+
+
+
+
+ +@endsection \ No newline at end of file diff --git a/resources/views/home/user/main.blade.php b/resources/views/home/user/main.blade.php new file mode 100644 index 0000000..2454608 --- /dev/null +++ b/resources/views/home/user/main.blade.php @@ -0,0 +1,41 @@ + + + + +
+ +
+
+ +
+ +
+
\ No newline at end of file diff --git a/resources/views/home/user/set.blade.php b/resources/views/home/user/set.blade.php index bd3cd17..11a221f 100644 --- a/resources/views/home/user/set.blade.php +++ b/resources/views/home/user/set.blade.php @@ -2,43 +2,7 @@ @section('container')
- - -
- -
-
- -
- -
-
- + @include('home.user.main')
@@ -73,7 +37,7 @@
- +
@@ -95,7 +59,7 @@ - +
diff --git a/resources/views/layouts/header.blade.php b/resources/views/layouts/header.blade.php index b5dab82..3db9471 100644 --- a/resources/views/layouts/header.blade.php +++ b/resources/views/layouts/header.blade.php @@ -34,8 +34,8 @@
  • {{ Auth::user()->name }} - - VIP3 + {{----}} + {{--VIP3--}}
    diff --git a/resources/views/layouts/panel.blade.php b/resources/views/layouts/panel.blade.php index edf1bdc..796faf3 100644 --- a/resources/views/layouts/panel.blade.php +++ b/resources/views/layouts/panel.blade.php @@ -59,7 +59,7 @@ 我发表的贴 我收藏的贴 @login - 发表新帖 + 发表新帖 @else 发表新帖 @endlogin diff --git a/routes/web.php b/routes/web.php index 4aaa7f9..3f1bbd8 100644 --- a/routes/web.php +++ b/routes/web.php @@ -13,12 +13,12 @@ //前台首页 Route::get('/','HomeController@index'); -//发表帖子页面 -Route::get('/post/add','PostController@add'); + //帖子详情 Route::resource('post','PostController',['only' => [ 'show','store' ]]); + //获取版块 Route::get('/getCategory','CategoryController@category'); @@ -32,22 +32,34 @@ Route::get('/reg','HomeController@regIndex'); //注册逻辑 Route::post('/reg','HomeController@reg'); - //退出登录 - Route::get('/logout','HomeController@logout'); - //设置页面 - Route::get('/set','UserController@set'); - //修改个人资料 - Route::post('/info','UserController@info'); - //上传头像 - Route::post('/upload','UserController@upload'); - //上传图片 - Route::post('/uploadImg','CommonController@file_up'); - //发出评论 - Route::post('/doComment','CommentController@doComment'); - //赞评论 - Route::get('/{id}/zan','CommentController@zan'); - //取消z赞 - Route::get('/{id}/unzan','CommentController@unzan'); + + //需要用户登录验证 + Route::group(['middleware'=>'checkLogin'],function (){ + //退出登录 + Route::get('/logout','HomeController@logout'); + //设置页面 + Route::get('/set','UserController@set'); + //修改个人资料 + Route::post('/info','UserController@info'); + //上传头像 + Route::post('/upload','UserController@upload'); + //上传图片 + Route::post('/uploadImg','CommonController@file_up'); + //用户中心 + Route::get('/index','UserController@index'); + //我的主页 + Route::get('/home','UserController@home'); + //发表帖子页面 + Route::get('/post/add','PostController@add'); + //发出评论 + Route::post('/doComment','CommentController@doComment'); + //赞评论 + Route::get('/{id}/zan','CommentController@zan'); + //取消z赞 + Route::get('/{id}/unzan','CommentController@unzan'); + }); + + });