title: passing value from controller to view undefined variable error
body: <pre><code>public function welcome()
  {
      $posts = new Post;
      $data = $posts-&gt;data();
  
      return view('welcome', compact("data"));
  }
  </code></pre>
  
  <p>Method in <strong>Post</strong> model:</p>
  
  <pre><code>public function data()
  { 
      return ['name ' =&gt; 'ABC', 'company'=&gt; 'com']; 
  }
  </code></pre>
  
  <p>This is Controller</p>
  
  <pre><code>{{ $data['name'] }}
  {{ $data['company'] }}
  </code></pre>
  
  <p>This is view</p>
  
  <p>I have passed value from controller to view and get undefined variable error</p>