-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathHomeController.php
More file actions
33 lines (29 loc) · 1.33 KB
/
HomeController.php
File metadata and controls
33 lines (29 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
namespace App\Http\Controllers;
use App\Cate;
use App\Tag;
use Illuminate\Http\Request;
use App\Article;
use App\Visit;
use Illuminate\Support\Facades\DB;
class HomeController extends Controller
{
//主页
public function home(Request $request)
{
$articles = Article::select(['ar.*', 'ca.name as cates'])->from('articles as ar')->where('is_hidden', 0)->leftjoin('cates as ca', 'ar.cate_id', '=', 'ca.id')->orderBy('is_top', 'desc')->orderBy('created_at', 'desc')->paginate(10);//->offset($offset)->limit(10)->get();
$articleCount = Article::all()->count();
$catesCount = Cate::all()->count();
$tagsCount = Tag::all()->count();
foreach ($articles as $article) {
$article->cover = imageURL($article->cover);
$article->content = str_limit(strip_tags($article->content_html), 500);
$article->created_at_date = $article->created_at;//->toDateString();
$article->updated_at_diff = $article->updated_at;//->diffForHumans();
$article->comments = $article->comments()->count();
$article->words = mb_strlen(strip_tags($article->content_html), 'UTF8');
$article->read = ceil($article->words / 1000);
}
return view(env('BLOG_THEME') . '.home', compact('articles', 'articleCount', 'catesCount', 'tagsCount'));
}
}