/**
  * Responds to requests to POST /books/create
  */
 public function postIndex(Request $request)
 {
     // first retrieve the salesperson list
     $salespeople = \App\Salesperson::orderBy('last_name')->get();
     // now filter the collection as needed based on user input
     //first filter on name / id if user entered a string
     $smatch = strtolower($request->input('salesperson'));
     if (isset($smatch) && $smatch != '') {
         $filtered = $salespeople->filter(function ($item) use($smatch) {
             return is_int(strpos(strtolower($item->last_name), $smatch)) || is_int(strpos(strtolower($item->employee_id), $smatch)) || is_int(strpos(strtolower($item->email), $smatch));
         });
         $salespeople = $filtered;
     }
     // now filter on city
     $smatch = strtolower($request->input('city'));
     if (isset($smatch) && $smatch != '') {
         $filtered = $salespeople->filter(function ($item) use($smatch) {
             return is_int(strpos(strtolower($item->city), $smatch));
         });
         $salespeople = $filtered;
     }
     // now filter on state
     $smatch = strtolower($request->input('state'));
     if (isset($smatch) && $smatch != '') {
         $filtered = $salespeople->filter(function ($item) use($smatch) {
             return is_int(strpos(strtolower($item->state), $smatch));
         });
         $salespeople = $filtered;
     }
     //now filter on active if not set to "Both"
     $active = $request->input('active');
     if ($active == 1) {
         // show only active
         $filtered = $salespeople->filter(function ($item) {
             return $item->termination_date == '0000-00-00' || is_null($item->termination_date) || $item->termination_date > getdate();
         });
         $salespeople = $filtered;
     } elseif ($active == 0) {
         // show only active
         $filtered = $salespeople->filter(function ($item) {
             return $item->termination_date != '0000-00-00' && $item->termination_date <= getdate();
         });
         $salespeople = $filtered;
     }
     // now return the view with the filtered list
     $request->session()->put('salespeople', $salespeople);
     $pcol = $request->session()->get('pcol');
     return view('salespeople', ['sortOrder' => $pcol], ['salespeople' => $salespeople]);
 }
 public function postIndex(Request $request, $sid, $mode)
 {
     if ($mode == 'Delete') {
         // use DB facade to delete the row matching $sid
         \App\Salesperson::destroy($sid);
         $request->session()->flash('message', 'Employee ID ' . $request->input('employee_id') . ' Deleted');
     } else {
         $this->validate($request, ['employeeID' => 'required|min:5', 'lastName' => 'required|min:2', 'firstName' => 'required|min:2', 'street1' => 'required|min:5', 'city' => 'required|min:2', 'state' => 'required|size:2', 'zipCode' => 'required', 'email' => 'email', 'hireDate' => 'required|date', 'terminationDate' => 'date']);
         // create a model and set the values, then session_save_path
         if ($mode == 'Edit') {
             // get the model from the db
             $salespeople = \App\Salesperson::where('id', '=', $sid)->get();
             $salesperson = $salespeople->first();
         } else {
             // instantiate a new model
             $salesperson = new \App\Salesperson();
         }
         // now set the model attributes
         $salesperson->employee_id = $request->input('employeeID');
         $salesperson->last_name = $request->input('lastName');
         $salesperson->first_name = $request->input('firstName');
         $salesperson->street1 = $request->input('street1');
         $salesperson->street2 = $request->input('street2');
         $salesperson->city = $request->input('city');
         $salesperson->state = $request->input('state');
         $salesperson->zip_code = $request->input('zipCode');
         $salesperson->email = $request->input('email');
         $salesperson->hire_date = $request->input('hireDate');
         $salesperson->termination_date = $request->input('terminationDate');
         if ($mode == 'Edit') {
             $salesperson->id = $sid;
         }
         $salesperson->save();
         $request->session()->flash('message', 'Salesperson ID ' . $salesperson->employee_id . ' Updated / Added');
     }
     $scol = $request->session()->get('scol');
     $sord = $request->session()->get('sord');
     $sord = $sord == 'A' ? 'D' : 'A';
     $request->session()->put('sord', $sord);
     // need to refresh the salespeople collection after changes
     $salespeople = \App\Salesperson::orderBy('employee_id')->get();
     // now put the collection in the session variable
     $request->session()->put('salespeople', $salespeople);
     // now direct to the sort route to retain the sort the user had before editing
     return redirect('salespeople/sort/' . $scol);
 }
            <?php 
$productlist = \App\Product::orderBy('product_name')->get();
?>
            {{-- loop through the product list and add to the dropdown --}}
            <select id="product" name="product">
                <option value="0">Select a Product</option>
                @foreach ($productlist as $product)
                    <option value="{{ $product->id }}">{{ $product->product_name }}</option>
                @endforeach
            </select>
        </div>
        <div class="field">
            <label for='salesperson'>Salesperson:</label>
            {{-- first load the salesperson list --}}
            <?php 
$salespersonlist = \App\Salesperson::orderBy('last_name')->orderBy('first_name')->get();
?>
            {{-- loop through the salesperson list and add to the dropdown --}}
            <select id="salesperson" name="salesperson">
                <option value="0">Select a Salesperson</option>
                @foreach ($salespersonlist as $salesperson)
                    <option value="{{ $salesperson->id }}">{{ $salesperson->last_name }}, {{ $salesperson->first_name }} ({{ $salesperson->employee_id }})</option>
                @endforeach
            </select>
        </div>

        <br><br>
        <label>&nbsp</label>
        <a class="formbutton" onclick="hidefilters()" title="Back" alt="Back" href="#">Cancel</a>
        <button onclick="hidefilters()" type="submit" id="submit" class="btn btn-primary showfilter">Apply</button>
    </form>