Thursday, March 30, 2017

Laravel 5.0 Undefined variable result

I have a form that a user enters and takes the entry and queries the database and returns to a view. I have managed to get one query working but when trying to work on another query it returns an undefined variable error in the view. See below:

Routes

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

Controller

class shopsalescontroller extends Controller

{

 public function index()
{
    $storeNum = request('storeNum');


   $result = shopsales::where('StoreNumber','=',$storeNum)
        ->get();

    return view('shopsales',compact('result'));


}

}

shopsales view

<section>
  <center><h1><STRONG>Query Data</STRONG></h1></center>
    <ul>
      @foreach ($result as $results)
        <li>Report Name =  | Report ID =  | Store Number =  | Store Name =  | Week Number =  |
            Year =  | PerfumeName =  | Units Sold =  | Sales = 
        </li>
        <br>
      @endforeach
    </ul>

</section>

I have used the exact code for the query that is working, struggling to understand why this is not.



via PA060

Advertisement