title: Eloquent relationship in Laravel
body: <p>I'm having following table structure:</p>
  
  <pre><code>Table Name - Users
      Column: id, name, email, etc
  
  Table Name - Plugins
      Column: id, theme_id, type_id, code,
  
  Table Name - Templates
      Column: id, theme_id, user_id, templatedata
  
  Table Name - Userplugins
      Column: id, user_id, plugins_id, contents
  </code></pre>
  
  <p>Now I'm calling the route with id of the <code>templates</code>, in which <code>templatedata</code> has <code>JSON</code> data, i'm able to get <code>Plugins</code> <code>code</code> by following code in my blade file as:</p>
  
  <pre><code>@foreach($gettemplate as $renderer)
  
      {!! $plugins-&gt;find($renderer)-&gt;code !!}
  
  @endforeach
  </code></pre>
  
  <p>but I'm unable to fetch contents in the <code>UserPlugins</code> table. Following is my <code>controller</code> where I'm trying to do so:</p>
  
  <pre><code>public function get_template($id)
  {
      $template = Template::findOrFail($id);
      $gettemplate = json_decode($template-&gt;templatedata);
      $plugins = Plugins::all();
      $user = User::findorFail($id);
      return $user-&gt;userplugins()-&gt;contents;
      //return view('nitseditor.test', ['plugins' =&gt; $plugins, 'gettemplate' =&gt; $gettemplate, 'user' =&gt; $user]);
  }
  </code></pre>
  
  <p>I've commented out my view just to check the output.
  I've defined the <code>relationship</code> in the <code>model</code> my <code>App/User.php</code> file contains:</p>
  
  <pre><code>public function userplugins(){
  
      return $this-&gt;hasMany('App\UserPlugin');
  }
  </code></pre>
  
  <p>And in <code>App\UserPlugin.php</code> file I've:</p>
  
  <pre><code>protected $fillable = [
  
      'contents',
  
  ];
  </code></pre>
  
  <p>I'm getting the following error:</p>
  
  <blockquote>
    <p>Undefined property: Illuminate\Database\Eloquent\Relations\HasMany::$contents</p>
  </blockquote>
  
  <p>Please help me out, Thanks.</p>