title: Laravel: How to create link buttons on a view dynamically?
body: <p>I'm making a College Administration website where a professor can log in.</p>
  
  <p>I have a dashboard, where my dynamically generated button should be placed: (right now it just has dummy buttons!)</p>
  
  <p><a href="https://i.stack.imgur.com/GzsxH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GzsxH.png" alt="dashboard"></a>
  Generated by this view file, which I will have to modify soon:</p>
  
  <pre><code>&lt;div class="container d-flex flex-column align-items-center justify-content-center"&gt;
  &lt;h1&gt;IA DASHBOARD&lt;/h1&gt;
  &lt;br&gt;
      &lt;div class="grid2"&gt;
              &lt;a href="{{ url('/subcode/{subcode}') }}" &gt;&lt;button class="btn btn-outline-primary btn-custom-outline-primary btn-custom"&gt;SUBCODE 1&lt;/button&gt;&lt;/a&gt;
              &lt;a href="{{ url('/subcode/{subcode}') }}" &gt;&lt;button class="btn btn-outline-primary btn-custom-outline-primary btn-custom"&gt;SUBCODE 2&lt;/button&gt;&lt;/a&gt;
              &lt;a href="{{ url('/subcode/{subcode}') }}" &gt;&lt;button class="btn btn-outline-primary btn-custom-outline-primary btn-custom"&gt;SUBCODE 3&lt;/button&gt;&lt;/a&gt;
          &lt;/div&gt;
  </code></pre>
  
  <p></p>
  
  <hr>
  
  <h2>Tables in the Database:</h2>
  
  <ul>
  <li>the table <code>iamarks</code> contains the data (student info, and marks) that is to be displayed after <code>/subcode/{subcode}</code> narrows it down to records of just the students that are in the class assigned to current logged-in professor. </li>
  <li><code>classroom_mappers</code> is a table used to map a professor to a classroom with a subject. It makes sure that one classroom only has one professor for a particular subject.</li>
  </ul>
  
  <hr>
  
  <p>the routes currently in my <strong><em>web.php</em></strong>:</p>
  
  <pre><code>route::get('/ia', 'IAController@show')-&gt;middleware('auth');
  Route::get('/subcode/{subcode}', 'IAController@showTable')-&gt;middleware('auth');
  </code></pre>
  
  <p>...and these are the methods inside my controller:</p>
  
  <pre><code>//shows buttons to the user:
  public function show(){
      $subcodes = DB::table('classroom_mappers')
                      -&gt;select('subcode')
                      -&gt;where([['PID','=', auth()-&gt;user()-&gt;PID]])
                      -&gt;get();
      return view('ia',compact('subcodes'));
  }
  
  //when user clicks a button, subcode is to be generated and a table is to be shown:
  //it works, I tried it by manually typing in subcode value in URL.
  
  public function showTable($subcode){
      $sem = DB::table('classroom_mappers')
                 -&gt;where([['PID','=', auth()-&gt;user()-&gt;PID],
                          ['subcode','=',$subcode]])
                 -&gt;pluck('semester');
      $division = DB::table('classroom_mappers')
                      -&gt;where([['PID','=', auth()-&gt;user()-&gt;PID],
                               ['semester','=',$sem],
                               ['subcode','=',$subcode]])
                      -&gt;pluck('division');
      $data = DB::table('iamarks')
                  -&gt;where([['semester','=',$sem],
                           ['division','=',$division],
                           ['subcode','=',$subcode]])
                  -&gt;get();
  
      return view('subcode',compact('data'));
  }
  
  </code></pre>
  
  <hr>
  
  <h2>My Problem:</h2>
  
  <p>To be able to generate the <code>{subcode}</code> in the URL dynamically, I want to create buttons in the dashboard using the data <code>$subcodes</code>. The controller hands over the <code>$subcodes</code> (an array of subject codes which belong to logged in professor) which are to be made into buttons from the <code>show()</code> method.  </p>
  
  <p>The buttons should have the name <code>{subcode}</code> and when clicked, should append the same subject code in the URL as <code>{subcode}</code>.</p>
  
  <ol>
  <li>How do I make use of <code>$subcodes</code> and make the buttons dynamically? </li>
  <li>How do I make sure the buttons made for one user are not visible to another user?</li>
  </ol>