title: Laravel5.6 "Call to a member function delete() on null " , delete a row in table
body: <p>I want to delete a row from table. The function I used in controller is:</p>
  
  <pre><code>public function destroy($id) {
      $category = Category::find($id);
      $category-&gt;delete();
      return redirect()-&gt;back();
  } 
  </code></pre>
  
  <p>However it throws me an error:</p>
  
  <blockquote>
    <p>Call to a member function delete() on null</p>
  </blockquote>
  
  <p>When I use this code:</p>
  
  <pre><code>public function destroy($id) {
      $category = Category::find($id);
      dd($id);
   } 
  </code></pre>
  
  <p>It is showing the correct id i.e.</p>
  
  <blockquote>
    <p>"1"</p>
  </blockquote>
  
  <p>And when I use</p>
  
  <pre><code>public function destroy($id) {
      $category = Category::find($id);
      dd($category); // or
      dd(Category::find($id);
   } 
  </code></pre>
  
  <p>I get the output</p>
  
  <blockquote>
    <p>null</p>
  </blockquote>
  
  <p>on the screen.</p>