title: passing data from controller to blade view laravel
body: <p>I am trying to send parameters through a href to a page from an events list to an event page.</p>
  
  <p>My route is </p>
  
  <pre><code> Route::get('eventpage', 'EventController@index')-&gt;name('eventpage');
  </code></pre>
  
  <p>And my event Controller is</p>
  
  <pre><code>&lt;?php
  namespace App\Http\Controllers;
  
  use Illuminate\Http\Request;
  use Illuminate\Support\Facades\DB;
  
     class EventController extends Controller
  {
  
  public function index(Request $request)
  {
      $id = $request-&gt;query('id');
      $event = DB::table('events')-&gt;where('id',$id)-&gt;get();
      $pics = DB::table('pictures')-&gt;where('event_id',$id)-&gt;get();
      $n = count($pics); // the number of pictures for a particular event
      return view('pages.eventPage');
  }
  </code></pre>
  
  <p>}</p>
  
  <p>The trouble is that for the first variable I try to use, $n, it gives me an error, "Undefined variable: n "</p>
  
  <p>My blade code is as follows</p>
  
  <pre><code>@for($i = 1; $i &lt; $n; $i++)
  &lt;li data-target="#carousel-example-generic" data-slide-to="{{ $i }}"&gt;&lt;/li&gt;
  @endfor
  </code></pre>
  
  <p>What am I doing wrong?</p>