Seems like your Post model might incorrectly extending Illuminate\Database\Eloquent\Model? But you don't show all of the relevant Post model class file.
Oct 29, 2022
18
Level 20
Showing error ..
Hello sir @jeffreyway , @Sinnbeck sir ..help me or anybody can able to help me! :) This error is coming from this episode https://laracasts.com/series/laravel-8-from-scratch/episodes/12?page=5only
Showing error, when I dd($posts) evrything is fine except the date is showing null also
my yamlFrontmatter code
---
title: My First Post
excerpt: Lorem Ipsum is simply dummy text of the printing and typesetting industry.
date: 2022-10-29
---
<p>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</p>
Too few arguments to function App\Models\Post::__construct(), 0 passed in C:\laragon\www\blog\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Concerns\HasAttributes.php on line
my model code
public $title;
public $date;
public $excerpt;
public $body;
public function __construct($title, $date, $excerpt, $body)
{
$this->title = $title;
$this->$date = $date;
$this->excerpt = $excerpt;
$this->body = $body;
}
my routes code
Route::get('/', function () {
$files = File::files(resource_path("posts"));
$posts = [];
foreach($files as $file)
{
$document = YamlFrontMatter::parseFile($file);
$posts[] = new Post(
$document->title,
$document->date,
$document->excerpt,
$document->body()
);
}
// dd($posts[3]->body);
return view('posts', compact('posts'));
});
Level 104
@Shivamyadav oh my... you're not doing well:
public function __construct($title, $date, $excerpt, $body, $slug)
{
$this->title = $title;
$this->date = $date;
$this->excerpt = $excerpt;
$this->body = $body;
$this->slug = $slug;
and
$posts[] = new Post(
$document->title,
$document->date,
$document->excerpt,
$document->slug, // not $slug
$document->body()
)
1 like
Please or to participate in this conversation.