/**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index(Request $request)
 {
     // Return all Artworks
     $term = $request->input('query');
     $dbField = $request->input('dbField');
     $sortBy = $request->input('sortBy');
     if (is_null($sortBy)) {
         $sortBy = 'artist_lastname';
     }
     if (is_null($term)) {
         $term = '';
     }
     if (is_null($dbField)) {
         $dbField = 'artist_lastname';
     }
     if (isset($term)) {
         $artworks = Artwork::where(strtolower($dbField), 'LIKE', '%' . $term . '%')->orderBy($sortBy, 'asc')->get();
     } else {
         $artworks = Artwork::all();
     }
     return view('artworks.index')->with('artworks', $artworks);
 }
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index(Request $request)
 {
     // request search query term & field for search
     $term = $request->input('query');
     $dbField = $request->input('dbField');
     $sortBy = $request->input('sortBy');
     if (is_null($sortBy)) {
         $sortBy = 'artist_fullname';
     }
     if (isset($term)) {
         if ($dbField == 'artist_lastname') {
             $artworks = Artwork::where(strtolower($dbField), 'ILIKE', '' . $term . '%')->orderBy($sortBy, 'asc')->get();
         } elseif ($dbField == 'art_fair_year') {
             $artworks = Artwork::where(strtolower($dbField), 'ILIKE', '%' . $term . '%')->orderBy($sortBy, 'asc')->get();
         } else {
             $artworks = Artwork::where(strtolower($dbField), 'ILIKE', '%' . $term . '%')->orderBy($sortBy, 'asc')->get();
         }
     } else {
         $artworks = Artwork::all();
     }
     // Pass in articles data to view
     return view('search.index', ['artworks' => $artworks]);
 }