@@ -22,7 +22,30 @@ public function __construct(Article $article, VisitorRepository $visitor)
2222
2323 /**
2424 * Get the page of articles without draft scope.
25- *
25+ *
26+ * @param Request $request
27+ * @param integer $number
28+ * @param string $sort
29+ * @param string $sortColumn
30+ * @return collection
31+ */
32+ public function pageWithRequest ($ request , $ number = 10 , $ sort = 'desc ' , $ sortColumn = 'created_at ' )
33+ {
34+ $ this ->model = $ this ->checkAuthScope ();
35+
36+ $ keyword = $ request ->get ('keyword ' );
37+
38+ return $ this ->model
39+ ->when ($ keyword , function ($ query ) use ($ keyword ) {
40+ $ query ->where ('title ' , 'like ' , "% {$ keyword }% " )
41+ ->orWhere ('subtitle ' , 'like ' , "% {$ keyword }% " );
42+ })
43+ ->orderBy ($ sortColumn , $ sort )->paginate ($ number );
44+ }
45+
46+ /**
47+ * Get the page of articles without draft scope.
48+ *
2649 * @param integer $number
2750 * @param string $sort
2851 * @param string $sortColumn
@@ -37,7 +60,7 @@ public function page($number = 10, $sort = 'desc', $sortColumn = 'created_at')
3760
3861 /**
3962 * Get the article record without draft scope.
40- *
63+ *
4164 * @param int $id
4265 * @return mixed
4366 */
@@ -48,7 +71,7 @@ public function getById($id)
4871
4972 /**
5073 * Update the article record without draft scope.
51- *
74+ *
5275 * @param int $id
5376 * @param array $input
5477 * @return boolean
@@ -82,7 +105,7 @@ public function getBySlug($slug)
82105
83106 /**
84107 * Check the auth and the model without global scope when user is the admin.
85- *
108+ *
86109 * @return Model
87110 */
88111 public function checkAuthScope ()
@@ -107,7 +130,7 @@ public function syncTag(array $tags)
107130
108131 /**
109132 * Search the articles by the keyword.
110- *
133+ *
111134 * @param string $key
112135 * @return collection
113136 */
0 commit comments