title: Toggle database value from View on button click Laravel
body: <p>I am using Laravel framework as a backend API and a few blade PHP files for the front end, specifically for the authentication and the admin panel from the /admin route. 
  In /admin, I display a list of all registered users and buttons next to them. (This page is only visible for users that have their value in Admin column set as true). I want to toggle the Admin status of a user, either promoting or demoting them by clicking the button next to the user name. 
  For this, I tried to use a form submit with get method. 
  I have a method defined inside UserController like this:</p>
  
  <pre><code>public function setAdmin($id) {
      $user = User::find($id);
      $user-&gt;admin = !$user-&gt;admin;
      if($user-&gt;save()) {
          echo "Changed";
      }
      else {
          echo "Could not be changed";
      }
  }
  </code></pre>
  
  <p>I want to call this method from the view on the click of a button.</p>
  
  <p>I tried using a Form to send a request by specifying the action, but it gave an error saying the values passed are less than the expected number of parameters.</p>
  
  <pre><code>{!! Form::open(['action' =&gt; ['UserController@setAdmin', $user-&gt;id], 'method' =&gt; 'POST']) !!}
  {{  Form::submit('Submit', ['class' =&gt; 'btn btn-primary']) }}
  {!! Form::close() !!}
  </code></pre>
  
  <p>I have a route set up explicitly to call this action</p>
  
  <pre><code>Route::post('/admin/users/setAdmin', 'UserController@setAdmin')
  </code></pre>
  
  <p>Although I am not sure if I have to set an explicit route for this action or if it's possible to call a controller function directly from a view without defining the route.</p>
  
  <p>I have iterated through User Model to display all users: </p>
  
  <pre><code>@if(count($users) &gt; 0) 
      @foreach($users as $user)
          &lt;div class="card"&gt;
              {{ $user }}
          &lt;/div&gt;
  
  
          {!! Form::open(['action' =&gt; ['UserController@setAdmin', $user-&gt;id], 'method' =&gt; 'POST']) !!}
          {{  Form::submit('Submit', ['class' =&gt; 'btn btn-primary']) }}
          {!! Form::close() !!}
      @endforeach
  @else 
      &lt;h2&gt;No users found!&lt;/h2&gt;
  @endif
  </code></pre>
  
  <p><strong>EDIT</strong>: Added the foreach section of the blade file. Also I modified the 'action' part of the Form::open() parameters, it was a mistype, the parameters error is still there.</p>
  
  <p>Can someone explain how this can be done?</p>