title: "Trying to get property 'id' of non-object (View: C:\xampp\htdocs\CERCAA\resources\views\admin\posts\edit.blade.php)"
body: <p>When I am editing my post then I am prompted with the following error message</p>
  
  <pre><code>Trying to get property 'id' of non-object (View: C:\xampp\htdocs\CERCAA\resources\views\admin\posts\edit.blade.php)
  
  public function update(Request $request, $id)
  {
      $this-&gt;validate($request, [
          'title' =&gt; 'required',
          'content' =&gt; 'required',
          'category_id' =&gt; 'required'
      ]);
  
      $post = Post::find($id);
  
      if($request-&gt;hasFile('featured'))
      {
          $featured = $request-&gt;featured;
  
          $featured_new_name = time() . $featured-&gt;getClientOriginalName();
  
          $featured-&gt;move('uploads/posts', $featured_new_name);
  
          $post-&gt;featured = 'uploads/posts/'.$featured_new_name;
  
      }
      $post-&gt;title = $request-&gt;title;
  
      $post-&gt;content = $request-&gt;content;
  
      $post-&gt;category_id = $request-&gt;category_id;
  
      $post-&gt;save();
  
      Session::flash('success', 'Post updated successfully.');
  
      return redirect()-&gt;route('posts');
  
  }
  </code></pre>
  
  <p>and blade code</p>
  
  <pre><code>&lt;div class="form-group"&gt;
  </code></pre>
  
  <p>Select a Category</p>
  
  <p></p>
  
  <p>@foreach($categories as $category)</p>
  
  <p>id}}"</p>
  
  <p>@if($post->$category->id == $category->name)</p>
  
  <p>selected</p>
  
  <p>@endif</p>
  
  <blockquote>
    <p>{{$category->name}}</p>
  </blockquote>
  
  <p>@endforeach</p>
  
  <p></p>
  
  <ul>
  <li><p>List item</p>
  
  <p></p></li>
  </ul>