77use App \Models \Product ;
88use Illuminate \Http \Request ;
99use App \Http \Controllers \Controller ;
10+
1011use App \Http \Resources \ShopResource ;
1112use Illuminate \Support \Facades \Auth ;
1213use App \Http \Resources \ProductResource ;
13-
14+ use Illuminate \ Support \ Facades \ Log ;
1415class SearchController extends Controller
1516{
1617 public function search ($ query ,$ userId ){
@@ -27,8 +28,12 @@ public function search($query,$userId){
2728 ->orWhere ("shop_description " ,"like " ,"% {$ query }% " )
2829 ->where ('state ' ,1 )
2930 ->take (5 )->get ();
30-
31+ Log::info ('SearchController: Search history ' , [
32+ "user_id " => $ userId ,
33+ "search_term " => $ query ,
34+ ]);
3135 if ($ userId !=0 ){
36+
3237 $ hystory =new History ;
3338 $ hystory ->user_id =$ userId ;
3439 $ hystory ->search_term =$ query ;
@@ -40,4 +45,14 @@ public function search($query,$userId){
4045 'shops ' => ShopResource::collection ($ shops ),
4146 ]);
4247 }
48+
49+ public function recentHistory (){
50+ $ user =Auth::guard ('api ' )->user ();
51+
52+ if (isset ($ user )){
53+ $ histories =History::where ('user_id ' ,$ user ->id )->get ();
54+ return response ()->json ($ histories );
55+ }
56+ return response ()->json ([]);
57+ }
4358}
0 commit comments