title: PHPUnit: Expected status code 200 but received 419 with Laravel
body: <p>I want to test the delete method but I am not getting the expected results from PHPUnit. I receive this message when running the test:</p>
  
  <pre><code> Expected status code 200 but received 419. Failed asserting that false is true.
   /vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestResponse.php:77
   /tests/Unit/CategoriesControllerTest.php:70
  </code></pre>
  
  <p>Laravel version: 5.5</p>
  
  <p>Thank you for any help!</p>
  
  <p>Controller constructor:</p>
  
  <pre><code>public function __construct()
  {
      $this-&gt;middleware('auth');
  
      $this-&gt;middleware('categoryAccess')-&gt;except([
          'index',
          'create'
      ]);
  }
  </code></pre>
  
  <p>Controller method:</p>
  
  <pre><code>public function destroy($categoryId)
  {
      Category::destroy($categoryId);
  
      session()-&gt;flash('alert-success', 'Category was successfully deleted.');
  
      return redirect()-&gt;action('CategoriesController@index');
  }
  </code></pre>
  
  <p>categoryAccess middleware:</p>
  
  <pre><code>public function handle($request, Closure $next)
  {
      $category = Category::find($request-&gt;id);
  
      if (!($category-&gt;user_id == Auth::id())) {
          abort(404);
      }
  
      return $next($request);
  }
  </code></pre>
  
  <p>Category model:</p>
  
  <pre><code>protected $dispatchesEvents = [
      'deleted' =&gt; CategoryDeleted::class,
  ];
  </code></pre>
  
  <p>Event listener</p>
  
  <pre><code>public function handle(ExpensesUpdated $event)
  {
      $category_id = $event-&gt;expense-&gt;category_id;
  
      if (Category::find($category_id)) {
          $costs = Category::find($category_id)-&gt;expense-&gt;sum('cost');
  
          $category = Category::find($category_id);
  
          $category-&gt;total = $costs;
  
          $category-&gt;save();
      }
  }
  </code></pre>
  
  <p>PHPUnit delete test:</p>
  
  <pre><code>use RefreshDatabase;
  
  protected $user;
  
  public function setUp()
  {
     parent::setUp();
     $this-&gt;user = factory(User::class)-&gt;create();
     $this-&gt;actingAs($this-&gt;user);
  }
  
  /** @test */
  public function user_can_destroy()
  {
      $category = factory(Category::class)-&gt;create([
          'user_id' =&gt; $this-&gt;user-&gt;id
      ]);
  
      $response = $this-&gt;delete('/category/' . $category-&gt;id);
  
      $response-&gt;assertStatus(200);
  
      $response-&gt;assertViewIs('category.index');
  }
  </code></pre>