Skip to content

Commit eb8cf7a

Browse files
committed
显示博客列表
1 parent dada08e commit eb8cf7a

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

app/Http/Controllers/WelcomeController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\Http\Controllers;
44

5+
use App\Blog;
56
use App\Mail\RegMail;
67
use Illuminate\Http\Request;
78

@@ -12,8 +13,7 @@ class WelcomeController extends Controller
1213
*/
1314
public function home()
1415
{
15-
// $user = \App\User::find(1);
16-
// \Mail::to($user)->send(new RegMail());
17-
return view('home');
16+
$blogs = Blog::orderBy('id', 'DESC')->with('user')->paginate(10);
17+
return view('home', compact('blogs'));
1818
}
1919
}

resources/views/home.blade.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,35 @@
2727
</div>
2828
</div>
2929
</form>
30+
31+
<div class="card mt-2">
32+
<div class="card-header">
33+
博客列表
34+
</div>
35+
<div class="card-body">
36+
<table class="table">
37+
<thead>
38+
<tr>
39+
<th>ID</th>
40+
<th>博客</th>
41+
<th>用户</th>
42+
<th width="150px">操作</th>
43+
</tr>
44+
</thead>
45+
<tbody>
46+
@foreach($blogs as $blog)
47+
<tr>
48+
<td scope="row">{{$blog['id']}}</td>
49+
<td>{{$blog['content']}}</td>
50+
<td>{{$blog->user->name}}</td>
51+
<td></td>
52+
</tr>
53+
@endforeach
54+
</tbody>
55+
</table>
56+
</div>
57+
<div class="card-footer text-muted">
58+
{{ $blogs->links() }}
59+
</div>
60+
</div>
3061
@stop

0 commit comments

Comments
 (0)