title: How to toggle a boolean value database field in Laravel
body: <p>I am creating a task list with a completed button for each task that needs to be able to reset the is_completed field from true to false within the tasks table. The user id is passed through a form and vue.js changes the status of the button text. My issue is with the controller file store function, as shown in the code below. Currently the button text does not change and there is no change in the database is_completed. The button does not react at all and there are no updates in the browser console.</p>
  
  <h3>index.blade.php</h3>
  
  <pre><code>&lt;div class="d-flex align-items-center pb-3"&gt;
  &lt;div class="h4"&gt;{{ $task-&gt;id }}&lt;/div&gt;
  
  &lt;follow-button user-id="{{ $user-&gt;id }}" follows="{{ $follows }}"&gt;&lt;/follow-button&gt;
  &lt;/div&gt;
  </code></pre>
  
  <h3>web.php</h3>
  
  <pre><code>Route::post('follow/{user}', 'FollowsController@store');
  </code></pre>
  
  <h3>FollowButton.vue</h3>
  
  <pre><code>&lt;template&gt;
    &lt;div&gt;
      &lt;button class="btn btn-primary ml-4" @click="followUser" v-text="buttonText"&gt;&lt;/button&gt;
    &lt;/div&gt;
  &lt;/template&gt;
  
  &lt;script&gt;
  export default {
      props: ['userId', 'follows'],
  
      mounted() {
          console.log('Component mounted.')
      },
  
      data: function () {
          return {
              status: this.follows,
          }
      },
  
      methods: {
          followUser() {
              axios.post('/follow/' + this.userId)
                  .then(response =&gt; {
                      this.status = ! this.status;
  
                      console.log(response.data);
                  })
                  .catch(errors =&gt; {
                      if (errors.response.status == 401) {
                          window.location = '/login';
                      }
                  }
              );
          }
      },
  
      computed: {
          buttonText() {
              return (this.status) ? 'Unfollow' : 'Follow';
          }
      }
  }
  &lt;/script&gt;
  </code></pre>
  
  <h3>FollowsController.php</h3>
  
  <pre><code>namespace App\Http\Controllers;
  
  use App\Profile;
  use App\User;
  use App\Task;
  use Illuminate\Http\Request;
  use Illuminate\Support\Facades\Auth;
  
  class FollowsController extends Controller
  {
      public function __construct()
      {
          $this-&gt;middleware('auth');
      }
  
      public function store(User $user)
      {
          return auth()-&gt;user()-&gt;following()-&gt;toggle($user-&gt;task);
      }
  }
  </code></pre>
  
  <p>Task.php</p>
  
  <pre><code>&lt;?php
  
  namespace App;
  
  use Illuminate\Database\Eloquent\Model;
  
  class Task extends Model
  {
  
  protected $casts = [
      'is_complete' =&gt; 'boolean',
  ];
  
  
  protected $fillable = [
      'title',
      'is_complete',
  ];
  
  
  public function user()
  {
      return $this-&gt;belongsTo(User::class);
  }
  }
  </code></pre>
  
  <p>User.php</p>
  
  <pre><code>&lt;?php
  namespace App;
  
  
  
  use App\Mail\NewUserWelcomeMail;
  
  use Illuminate\Notifications\Notifiable;
  
  use Illuminate\Contracts\Auth\MustVerifyEmail;
  
  use Illuminate\Foundation\Auth\User as Authenticatable;
  
  use Illuminate\Support\Facades\Mail;
  
  
  
  class User extends Authenticatable
  
  {
  
  use Notifiable;
  
  
  
  protected $fillable = [
  
      'username', 'password',
  
  ];
  
  
  
  
  protected $hidden = [
  
      'password', 'remember_token',
  
  ];
  
  
  
  
  
  protected $casts = [
  
      'email_verified_at' =&gt; 'datetime',
  
  ];
  
  
  
  protected static function boot()
  
  {
  
      parent::boot();
  
  
  
      static::created(function ($user) {
  
          $user-&gt;profile()-&gt;create([
  
              'title' =&gt; $user-&gt;username,
  
          ]);
  
  
  
  
      });
  
  }
  
  
  
  public function posts()
  
  {
  
      return $this-&gt;hasMany(Post::class)-&gt;orderBy('created_at', 'DESC');
  
  }
  
  
  
  public function following()
  
  {
  
      return $this-&gt;belongsToMany(Profile::class);
  
  }
  
  
  
  public function profile()
  
  {
  
      return $this-&gt;hasOne(Profile::class);
  
  }
  
  
  
  
  
  public function tasks()
  {
      return $this-&gt;hasMany(Task::class);
  }
  
  }
  class User extends Authenticatable
  
  {
  
  use Notifiable;
  
  
  
  
  
  protected $fillable = [
  
      'username', 'password',
  
  ];
  
  
  protected $hidden = [
  
      'password', 'remember_token',
  
  ];
  
  
  protected $casts = [
  
      'email_verified_at' =&gt; 'datetime',
  
  ];
  
  
  
  protected static function boot()
  
  {
  
      parent::boot();
  
  
  
      static::created(function ($user) {
  
          $user-&gt;profile()-&gt;create([
  
              'title' =&gt; $user-&gt;username,
  
          ]);
  
  
  
  
      });
  
  }
  
  
  
  public function posts()
  
  {
  
      return $this-&gt;hasMany(Post::class)-&gt;orderBy('created_at', 'DESC');
  
  }
  
  
  
  public function following()
  
  {
  
      return $this-&gt;belongsToMany(Profile::class);
  
  }
  
  
  
  public function profile()
  
  {
  
      return $this-&gt;hasOne(Profile::class);
  
  }
  
  
  
  
  
  public function tasks()
  {
      return $this-&gt;hasMany(Task::class);
  }
  
  }
  </code></pre>