@@ -22,14 +22,16 @@ class ArticleController extends Controller
22
22
*/
23
23
public function list ()
24
24
{
25
- $ articles = Article::where ('is_hidden ' , 0 )->orderBy ('created_at ' , 'desc ' )->paginate (10 );
26
- for ($ i =0 ; $ i < sizeof ($ articles ); $ i ++) {
27
- $ articles [$ i ]->content = str_limit (strip_tags ($ articles [$ i ]->content_html ), 150 );
28
- $ articles [$ i ]->created_at_date = $ articles [$ i ]->created_at ->toDateString ();
29
- $ articles [$ i ]->updated_at_diff = $ articles [$ i ]->updated_at ->diffForHumans ();
30
- }
31
- $ tags = Tag::all ();
32
- return view ('articles.list ' , compact ('articles ' , 'tags ' ));
25
+ $ articles = Article::where ('is_hidden ' , 0 )->orderBy ('created_at ' , 'desc ' )->paginate (10 );
26
+ foreach ($ articles as $ article ) {
27
+ $ article ->cover = imageURL ($ article ->cover );
28
+ $ article ->content = str_limit (strip_tags ($ article ->content_html ), 150 );
29
+ $ article ->created_at_date = $ article ->created_at ->toDateString ();
30
+ $ article ->updated_at_diff = $ article ->updated_at ->diffForHumans ();
31
+ }
32
+
33
+ $ tags = Tag::all ();
34
+ return view ('articles.list ' , compact ('articles ' , 'tags ' ));
33
35
}
34
36
35
37
/**
@@ -39,17 +41,19 @@ public function list()
39
41
*/
40
42
public function search (Request $ request )
41
43
{
42
- $ key = $ request ->key ;
43
- $ articles = Article::when ($ key , function ($ query ) use ($ key ){
44
- return $ query ->where ('title ' , 'like ' , '% ' .$ key .'% ' );
45
- })->where ('is_hidden ' , 0 )->orderBy ('created_at ' , 'desc ' )->paginate (10 );
46
- for ($ i =0 ; $ i < sizeof ($ articles ); $ i ++) {
47
- $ articles [$ i ]->content = str_limit (strip_tags ($ articles [$ i ]->content_html ), 150 );
48
- $ articles [$ i ]->created_at_date = $ articles [$ i ]->created_at ->toDateString ();
49
- $ articles [$ i ]->updated_at_diff = $ articles [$ i ]->updated_at ->diffForHumans ();
50
- }
51
- $ tags = Tag::all ();
52
- return view ('articles.list ' , compact ('articles ' , 'tags ' ));
44
+ $ key = $ request ->key ;
45
+ $ articles = Article::when ($ key , function ($ query ) use ($ key ){
46
+ return $ query ->where ('title ' , 'like ' , '% ' .$ key .'% ' );
47
+ })->where ('is_hidden ' , 0 )->orderBy ('created_at ' , 'desc ' )->paginate (10 );
48
+ foreach ($ articles as $ article ) {
49
+ $ article ->cover = imageURL ($ article ->cover );
50
+ $ article ->content = str_limit (strip_tags ($ article ->content_html ), 150 );
51
+ $ article ->created_at_date = $ article ->created_at ->toDateString ();
52
+ $ article ->updated_at_diff = $ article ->updated_at ->diffForHumans ();
53
+ }
54
+
55
+ $ tags = Tag::all ();
56
+ return view ('articles.list ' , compact ('articles ' , 'tags ' ));
53
57
}
54
58
55
59
/**
@@ -76,11 +80,7 @@ public function show(Request $request, $id)
76
80
}
77
81
if ($ comment ->user_id == 1 ) {
78
82
$ comment ->master = User::select ('name ' , 'avatar ' )->findOrFail (1 );
79
- if ($ comment ->master ->avatar ) {
80
- $ comment ->master ->avatar = MyUpload::generateUrl ($ comment ->master ->avatar );
81
- }else {
82
- $ comment ->master ->avatar = '/images/default-avatar.png ' ;
83
- }
83
+ $ comment ->master ->avatar = imageURL ($ comment ->master ->avatar );
84
84
}
85
85
86
86
// $comment->replys = $comment->replys;
@@ -96,11 +96,7 @@ public function show(Request $request, $id)
96
96
}
97
97
if ($ reply ->user_id == 1 ) {
98
98
$ reply ->master = User::select ('name ' , 'avatar ' )->findOrFail (1 );
99
- if ($ reply ->master ->avatar ) {
100
- $ reply ->master ->avatar = MyUpload::generateUrl ($ comment ->master ->avatar );
101
- }else {
102
- $ reply ->master ->avatar = '/images/default-avatar.png ' ;
103
- }
99
+ $ reply ->master ->avatar = imageURL ($ reply ->master ->avatar );
104
100
}
105
101
}
106
102
}
0 commit comments