Exemple #1
0
 public function indexHtml(Request $request)
 {
     $pid = $request->input('pid');
     $cat_id = $request->input('cat_id');
     $Tips = Tip::all();
     if ($pid || $cat_id) {
         if ($pid) {
             $Tips = Tip::where('place_id', $pid);
         }
         if ($cat_id) {
             $Tips = Tip::where('cat_id', $cat_id);
         }
         $Tips = $Tips->get();
     }
     foreach ($Tips as $tip) {
         $tip->name = User::find($tip->user_id)->name;
         $tip->username = User::find($tip->user_id)->username;
         $tip->answers = Tip::where('parent_id', $tip->id)->get();
         foreach ($tip->answers as $i => $value) {
             $answer = $tip->answers[$i];
             $answer->name = User::find($answer->user_id)->name;
             $answer->username = User::find($answer->user_id)->username;
         }
     }
     return view('places.index', ['tips' => $Tips]);
 }
 public function tips()
 {
     $now = Carbon::now();
     $tips = Tip::where('start', '<', $now)->where('end', '>', $now)->get();
     return response()->json(['tips' => $tips]);
 }