0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Creating default object from empty valueというエラーの原因

Posted at

背景

Laravelで更新機能を作っており更新ボタンを押すとこのエラーに遭遇した。

Creating default object from empty value

スクリーンショット 2020-01-27 16.37.20.png

該当コード

PostController
$post->user_id = auth()->id();
$post->title = $request->title;
$post->clearTime = $request->clearTime;
$post->save();

原因と解決方法

$postのクラス宣言をしていないため。

$post = new Post; #追加
$post->user_id = auth()->id();
$post->title = $request->title;
$post->clearTime = $request->clearTime;
$post->save();

を最初に追加してあげる

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?