title: Trying to get property 'id' of non-object laravel
body: <p>can someone to help me ? i have an error Trying to get property 'id' of non-object laravel while try to show my edit form</p>
  
  <p>this is my controller</p>
  
  <pre><code>public function edit($id)
  {
      $produk = produk::where('id',$id)-&gt;first();
      return view('produk.edit',compact('produk'));
  }
  
  
  public function update(Request $request, $id)
  {
      produk::where('id',$id)
          -&gt;update([
              'nama' =&gt; $request-&gt;nama,
              'id_kategori' =&gt; $request-&gt;kategori,
              'qty' =&gt; $request-&gt;qty,
              'harga_beli' =&gt; $request-&gt;beli,
              'harga_jual' =&gt; $request-&gt;jual,
          ]);
     return redirect()-&gt;route('produk.index');
  }
  </code></pre>
  
  <p>this is my model</p>
  
  <pre><code>&lt;?php
  
  namespace App;
  
  use Illuminate\Database\Eloquent\Model;
  
  class produk extends Model
  {
      protected $guarded = ['id','created_at','updated_at'];
  
      public function kategoris()
      {
          return $this-&gt;hasOne('App\kategori', 'id', 'id_kategori');
      }
  }
  </code></pre>
  
  <p>and this is my view</p>
  
  <pre><code>&lt;select class="form-control" name="kategori"&gt;
      &lt;option value="Pilih Kategori"&gt;&lt;/option&gt;
      @foreach ($produk as $k)
          &lt;option value="{{ $k-&gt;id }}" @if($produk-&gt;id_kategori == $k-&gt;id) selected @endif&gt;{{$k-&gt;nama}}&lt;/option&gt;
      @endforeach
  &lt;/select&gt;
  </code></pre>