Wednesday, March 29, 2017

Laravel 5.0 query database using a form

I am new to Laravel 5.0 and I'm having trouble using a form to query a database and return the results to a view. Form accepts user input for week number and this week number should be used to query the database table. Any help would be appreciated.

Form inside my view

<form action="" method="get">
    
    <div class="input-group">
       <input type="text" class="form-control" name="weekNum" placeholder="Typein Week Number"> 
       <span class="input-group-btn"> 
           <button type="submit" class="btn btn-default">
               <span class="glyphicon glyphicon-search"></span>
           </button>
       </span>
   </div>
</form>

Route::get('/search', 'shopsalescontroller@index');

Controller

class shopsalescontroller extends Controller
{
    public function index()
    {
        $weekNum = Request::input('WeekNumber');
        $result = shopsales::where('WeekNumber','=',$weekNum)->get();
        return $result; 
    }
}



via PA060

Advertisement