title: Perform specific action on button in Bootstrap modal (Laravel)
body: <p>I created a modal which displays information specific to their id entries and placed the Approve and Reject button as below.</p>
  
  <p><a href="https://i.stack.imgur.com/sYfbM.jpg" rel="nofollow noreferrer">Screenshot of modal</a></p>
  
  <p>When a user click on "Accept" or "Reject", it needs to pass id related to the viewed entries so the user can perform the requested action, whether to accept or reject the entries (default status is 'pending').</p>
  
  <p><strong>vendor.blade.php</strong></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="modal-footer"&gt;
    &lt;span class="pull-left"&gt;
      &lt;form method="POST" action="{{ route('approve') }}"&gt;
        @method('PUT')
        @csrf
        &lt;button type="submit" class="btn btn-success"&gt;Approve&lt;/button&gt;
       &lt;/form&gt;
    &lt;/span&gt;
    &lt;span class="pull-right"&gt;
      &lt;form method="POST" action="{{ route('reject') }}"&gt;
        @method('PUT')
        @csrf
        &lt;button type="submit" class="btn btn-danger"&gt;Reject&lt;/button&gt;
      &lt;/form&gt;
    &lt;/span&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>In <strong>VendorController.php</strong></p>
  
  <pre><code>public function index()
  {
      $vendors = DB::select('select company_name, roc_no, created_at from mides_vendors');
  
      $vendor_id = Vendor::where('status', 'Pending');
  
      return view('panel.vendor', ['vendors' =&gt; $vendors]);
  }
  </code></pre>
  
  <p><strong>ApprovedVendorController.php</strong></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?php
  
  namespace App\Http\Controllers;
  
  use App\User;
  use App\Vendor;
  use Illuminate\Http\Request;
  use Illuminate\Support\Facades\DB;
  
  class ApproveVendorController extends Controller
  {
      public function approve(Request $request, $id)
      {
       DB::insert('insert into mides_users(name, email, password) select name,roc_no,password from mides_vendors where id = :id', ['id' =&gt; $id]);
       DB::update('update mides_vendors set status = :status where id = :id', ['status' =&gt; 'Approved', 'id' =&gt; $id]);
  
       return redirect('/');
      }
  
      public function reject(Request $request, $id)
      {
       DB::update('update mides_vendors set status = :status where id = :id', ['status' =&gt; 'Rejected', 'id' =&gt; $id]);
  
       return redirect('/');
      }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p><strong>routes/web.php</strong></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>Route::prefix('/panel')-&gt;group(function () {
   Route::get('/dashboard', function () {
    return view('panel.dashboard');
   });
    /* These routes only display the information/modal
   Route::get('/approve-vendor', 'VendorController@showNewRegistration'); // return vendor.blade.php
   Route::get('/vendor-approved', 'VendorController@showApproved'); // return vendor-approve.blade.php
   Route::get('/vendor-reject', 'VendorController@showRejected'); // return vendor-reject.blade.php
    /* These route used to perform the specific action */
   Route::put('/approve/{id}', 'ApproveVendorController@approve')-&gt;name('approve');
   Route::put('/reject{id}', 'ApproveVendorController@reject')-&gt;name('reject');
  });</code></pre>
  </div>
  </div>
  </p>
  
  <p>However, it returns this error.</p>
  
  <p><a href="https://i.stack.imgur.com/248Mr.jpg" rel="nofollow noreferrer">Error got after clicking Accept or Reject</a></p>
  
  <p>How do I pass the id of data? I tried as shown in <a href="https://stackoverflow.com/questions/39827189/pass-the-database-value-to-modal-popup">pass the database value to modal popup</a> to create the modal using second answer option (besides the ajax ones). Do I need to create another controller for these?</p>
  
  <p>Edited: after do as explained by @Wreigh, it works, means that the status changed from 'pending' to 'accept/reject'. But, when I return to the previous page, which is the <code>/panel/approve-vendor</code> (the page is used for showing the pending list modal) then I got the error <code>undefined variable vendorId</code>.</p>