Level 102
Shouldnt that just be
$post->image = $image,
this is the error i am getting when i tried to create a post with image Attempt to assign property "image" on null
public function createPost()
{
if (auth()->check()) {
$this->validate();
$post = Post::create([
'user_id' => auth()->user()->id,
'title' => $this->title,
'category_id' => $this->category,
'body' => $this->body,
'slug' => Str::slug($this->title),
$image = $this->photo->storeAs('posts/', Str::random(30)),
$this->post->image = $image,
// $this->post->save()
// session()->flash("message", "Featured image successfully uploaded");
]);
$users = auth()->user();
$users->increment('points', 10);
session()->flash('success_message', 'Post was added successfully!');
$this->reset();
return redirect()->route('post.index');
}
Also you arent closing the array inside create() correctly
$post = Post::create([
'user_id' => auth()->user()->id,
'title' => $this->title,
'category_id' => $this->category,
'body' => $this->body,
'slug' => Str::slug($this->title),
]); //closing goes here
$image = $this->photo->storeAs('posts/', Str::random(30)),
$post->image = $image,
$post->save(); //remove $this here has well
// session()->flash("message", "Featured image successfully uploaded");
Please or to participate in this conversation.