mercredi 5 avril 2017

laravel 5.2 if else to query database

stuck on a form that allows the user to enter a value into a choice of two fields. I can query the database using one field but want to add more range to database queries. With the following code below when i try to access the page to query it just shows me a white screen.

public function index()
 {
   $data = $request->all();

   if(!empty($data['pstoreNum']))
   {
   $pstoreNum = $data['pstoreNum'];


    $result = DB::table('perfumes')->where('StoreNumber','=',$pstoreNum)
              ->get();

    return view('perfumes',compact('result'));
  } 
  else if(!empty($data['pweekNum']))
  {
      $pweekNum = $data['pweekNum'];


      $result = DB::table('perfumes')->where('WeekNumber','=',$pweekNum)
             ->get();

       return view('perfumes',compact('result'));
   }

  }

My routes file simple calls the index function. Any help would be appreciated.

Aucun commentaire:

Enregistrer un commentaire