title: Attempt to read property "title" on array (Error Exception) Laravel Php
body: <blockquote>
  <p>when I try to run the following it gives the Error Exception where it can't read the title on array. Can you let me know how to fix this?</p>
  </blockquote>
  <p>**My post code from app/models and as below **</p>
  <pre><code> &lt;?php
  
  
  namespace App\Models;
  
  use Illuminate\Database\Eloquent\ModelNotFoundException; //
  use Illuminate\Support\Facades\File;
  
  class Post
  {   
      public $title;
  
      public $excerpt;
  
      public $date;
      
      public $body;
  
      public function __construct($title, $excerpt, $date, $body)
      {
          $this-&gt; title = $title;              //this is where the error is occurring 
          $this-&gt; excerpt = $excerpt;
          $this-&gt; date = $date;
          $this-&gt; body = $body;
      }
  
      public static function all() 
      {
          $files = File::files(resource_path(&quot;postss/&quot;));
  
        return  array_map(function ($file){
              return $file-&gt; getContents();
          }, $files);
          
      
      }
  
      public static function find($slug)
      {
          
          base_path();
  
           if (!file_exists($path = resource_path(&quot;postss/{$slug}.html&quot;))) {
              throw new ModelNotFoundException();
          }
      
          return cache()-&gt; remember(&quot;posts.{$slug}&quot;, 7 , function () use ($path){
             
           return file_get_contents($path);
      
          });
      
      
          
        
         
  
      }
  
  
  }
  </code></pre>
  <p><strong>and my routes class code is</strong></p>
  <pre><code>Route::get('/', function () {
    
      $files = File::files(resource_path(&quot;postss&quot;));
      $posts =[];
  
      foreach ($files as $file) {
         $document[] = YamlFrontMatter::parseFile($file);
         $posts[]= new Post(
             $document-&gt;title,
             $document-&gt;excerpt,
             $document-&gt;date,
             $document-&gt;body()
         );
      }
  });
  </code></pre>
  <blockquote>
  <p>The code is right as far as i know, I just don't know if there is something I need to add or do something to make the error go away.</p>
  </blockquote>